{"id":317525,"date":"2020-07-27T07:36:49","date_gmt":"2020-07-27T14:36:49","guid":{"rendered":"https:\/\/css-tricks.com\/?p=317525"},"modified":"2020-07-27T07:36:50","modified_gmt":"2020-07-27T14:36:50","slug":"bold-on-hover-without-the-layout-shift","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/bold-on-hover-without-the-layout-shift\/","title":{"rendered":"Bold on Hover… Without the Layout Shift"},"content":{"rendered":"\n

When you change the font-weight<\/code> of a font, the text will typically cause a bit of a layout shift. That’s because bold text is often larger and takes up more space. Sometimes that doesn’t matter, like a vertical stack of links where the wider\/bolder text doesn’t push anything anyway. Sometimes it does<\/em> matter, like a horizontal row where the wider\/bolder text pushes other elements away a smidge. <\/p>\n\n\n\n

Ryan Mulligan demonstrates<\/a>:<\/p>\n\n\n\n\n\n\n\n

Bolding text on mouse hover causes a layout shift that’s especially noticeable when elements start wrapping. Here’s a nifty trick: add a hidden pseudo element with the same text string but set it to the bold font size 🙌

See it on
@CodePen<\/a>: https:\/\/t.co\/kBzZXqqtmi<\/a> pic.twitter.com\/kdZBTLQ0RD<\/a><\/p>\u2014 Ryan Mulligan (@hexagoncircle) July 20, 2020<\/a><\/blockquote>