DEV Community

Tom
Tom

Posted on

Underline a link in 2021

Underlining a link doesn't involve a border-bottom anymore, as I discovered on CSS Tricks:

a {
  text-decoration-color: #f60;
  text-decoration-thickness: 1px;
  text-decoration-skip-ink: auto; /* default */
  text-underline-offset: 1.5px;
}
Enter fullscreen mode Exit fullscreen mode

Very handy and way more flexible!

Top comments (4)

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️ • Edited

It seems text-decoration-thickness is not yet animateable in chromium with transition 😭


I have to correct myself: CSS Houdini makes this possible ✨🧙✨:

<h1>Hello, World!</h1>

<style>
  @property --thickness {
    syntax: "<length>";
    inherits: true;
    initial-value: 0px;
  }
  h1 {
    --duration: .3s;
    --thickness: .1em;
    text-decoration: underline;
    text-decoration-color: black;
    text-decoration-thickness: var(--thickness);

    transition: --thickness var(--duration);
  }
  h1:hover {
    --thickness: .2em;
  }
</style>
Enter fullscreen mode Exit fullscreen mode
Collapse
 
marcellothearcane profile image
marcellothearcane

What's the support like?

Collapse
 
ludder profile image
Tom • Edited

It's quite OK, but of course that depends on the browsers you have to support, for example: caniuse.com/?search=text-decoratio...

Collapse
 
roileo profile image
roiLeo

as always can't be used with ie11