Styling Text Decoration Thickness
Posted:
Okay, this will likely be a short one.
I did not know there was a CSS property to style text-decoration thickness.
"Back in the day" I would generally disable text-decoration and use a border-bottom on text/link hover. But the "problem" with this was that you would get the a small jump when the non-hovered/decorated version would suddenly get a border-bottom. The fix was easy, just add a transparent border with the same thickness as the decoration.
But that's more CSS than we actually need.
In comes the text-decoration-thickness property!
Checkout the CodePen below. When hovering over "No invisible border", notice the jump? Now hover over "Invisible border." See the lack of jump? This is how I would prevent this back in the day; the same thickness border on non-hover, just invisible. The space is now "reserved" for when the non-invisible border is present.
Now, with text-decoration-thickness we no longer need that additional border. Hover over "Standard Text Decoration", see the thin, hard to see underline? This is not a border but actual text/characters.
Lastly, hover over "Standard Text Decoration with thickness" and you will see a much thicker underline that is also not a border.
But it gets a bit cooler than that! The text-decoration-thickness property can take a PX value, a percentage value, "auto"; which leaves it up to the browser, and finally, "from-font". "From-font" looks at the font being used on the element and checks if a thickness is set within the font file itself. If there is one, it's used, otherwise it falls back to "auto" and lets the browser determine.