CSS: currentColor Value

koralarts

Karl Castillo

Posted on May 3, 2020

CSS: currentColor Value

The CSS property currentColor is an interesting property where the value of currentColor is your element's current font colour. This value can be used as a named colour.

div {
  color: red;
  border: 1px solid currentColor;
}
Enter fullscreen mode Exit fullscreen mode

Like other CSS properties, currentColor is affected by cascade and specificity.

<div>I'm Red</div>
<div class="div-blue">I'm Blue</div>
Enter fullscreen mode Exit fullscreen mode
div {
  color: red;
  border: 1px solid currentColor;
}

.div-blue {
  color: blue;
}
Enter fullscreen mode Exit fullscreen mode

So what can we do with currentColor?


SVG Fill

a {
 color: blue;
}

a > svg {
  fill: currentColor;
}
Enter fullscreen mode Exit fullscreen mode

Theming


Can you think of other ways to use currentColor?

💖 💪 🙅 🚩
koralarts
Karl Castillo

Posted on May 3, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related