Using currentColor in 2025

Chris Coyier Chris Coyier on

Gotta give props to currentColor. It’s a keyword in CSS that is the OG variable. It wasn’t always there, but it was relatively usable in browsers by, say, 2010.

currentColor is a value, that you have control over, that represents something else.

.card {
  color: red;
  border: 3px solid currentColor;
}Code language: CSS (css)

What do you think the color of that border is gonna be? Not a trick question, it’s red my friend. You don’t have to type red twice. You don’t have to worry those colors that you’ve so elegantly tied together are going to drift apart. The power of computer programming lives here.

The value currentColor resolves to is whatever the color value resolves to at the element being effected by the selector. The color property cascades, so it could be set three levels up from the current element, or not at all, or whatever. It’ll always be something.

p.s. it can be currentColor, currentcolor, CURRENTCOLOR, cUrrENtCoLOr or whatever. CSS is unbothered. Just spel it right.

Hard Times

Business just isn’t rolling in thick anymore for currentColor. Search a 10 year old codebase and you’ll find a few hits, but these days, custom properties are a far more popular choice. Are you turning your back on an old friend? Yes. Is new friend better? Also yes. Just saying.

.card {
  --mainColor: red;
 
  color: var(--mainColor);
  border: 3px solid var(--mainColor);
}Code language: CSS (css)

This does the same thing. It’s an extra line of code, but your fellow computer programmers will all agree that it’s much more clear and versatile.

Versatile?

Definitely. Custom properties can be just about anything. It’s almost weird how permissive the value of a custom property can be. But it’s certainly not just colors. Hopefully obviously: currentColor only references color. There is no currentPadding or currentEmotionalState or anything.

Bugs?

I figured I’d have a play for old times sake. While I was doing that, I noticed a few oddities.

body {
  color: orange;
  accent-color: currentColor; /* doesn't work 🤷‍♀️ */
}Code language: CSS (css)

That one just doesn’t work (across the three major browsers I tried). Why? No I’m asking you. lol.

Here’s another:

body {
  color: rebeccaPurple;
}
button {
  border: 1px solid currentColor;
}Code language: CSS (css)

That one isn’t a bug, I suppose, as the trouble is that user agent stylesheets tend to set the color of buttons themselves (e.g. color: buttontext;), so if you want it to work, you’ll have to set the color explicitly, or force inherit it.

button {
  color: inherit;
  border: 1px solid currentColor;
}Code language: CSS (css)

I also swore I found an issue with relative color syntax and currentColor, but now that I’m typing and fact checking I can’t find it again so I’ll just leave it at that.

But is it still cool though?

I feel like I’ve made the point that it’s not amazingly useful anymore, but I might also argue that it’s not a terrible idea when the intentionality matches up just right. For instance, say you’ve got icons where the fill should always match the text color. That’s a fine use case really.

nav {
  color: salmon;

  svg.icon {
    fill: currentColor;
  }
}Code language: CSS (css)

Another step further, we could pop a little shadow on those icons that is based on that color.

nav {
  color: salmon;

  svg.icon {
    fill: currentColor;
    filter: drop-shadow(
      0 1px 0 oklch(from currentcolor calc(l - 0.25) c h));
  }
}Code language: CSS (css)

Here’s a video of that and some other stuff working together. No custom properties here, all currentColor:

I have stuck in my memory a Simurai post from 2014 where he showed off the power of this as well.

Nice.

Wanna be a better designer?

Frontend Masters logo

Sarah Drasner is a heck of a designer, and has a wonderful course called Design for Developers where you'll learn to be a self-sufficient designer.

7-Day Free Trial

9 responses to “Using currentColor in 2025”

  1. Ben Reeves says:

    The one place I have found currentColor to be really useful is in SVG icons. It allows you to create an icon and drop it in to any flow and have it work. The only downside is that you have to use the SVG code inline and can’t load it with an img tag.

    • Chris Coyier says:

      I wonder if there is some interesting way around that, like using the img as a mask somehow so you can use background-color that inherits the currentColor instead or something.

    • Dwight Frederick says:

      I usually just apply an svg selector and give it the color of the parent there.

    • Puspam Adak says:

      You can actually keep your SVG code in a seperate file and just it inside your HTML code:

      The part after # is the ID of the SVG root tag in the external file:
      <svg id="root">......<svg>

      The only downside of this approach is that the browser can’t determine the aspect ratio of the graphic automatically. But that won’t cause any problem if you only use icons with a square viewbox.

  2. Qing Charles says:

    You spelt currentColor wrong in your 2nd paragraph, which is ironic. Or is it? I can never remember the rules about irony 🙂

  3. Ana Tudor Ana Tudor says:

    I also swore I found an issue with relative color syntax and currentColor, but now that I’m typing and fact checking I can’t find it again so I’ll just leave it at that.

    Chrome? I have filed at least a couple of bugs myself (one of which I know for sure got fixed) and other issues I hit already had bugs filed. So it’s possible the issue already got fixed.

  4. Sarah S says:

    I believe I read from either Andy Bell or Heydon Pickering years ago about avoiding using CSS custom properties. I think the argument was using Sass variables instead to avoid having the browser do more calculations upfront to figure out the CSS var values…

    My question is, is there any sort of performance overhead to choosing a CSS var instead of currentColor? It seems like there might be, where browsers are more optimized to know “currentColor = parent color,” vs browsers encountering a CSS var and not knowing what it could be.

    • Chris Coyier says:

      I believe I read from either Andy Bell or Heydon Pickering years ago about avoiding using CSS custom properties.

      I’d be rather shocked if that were true.

      My question is, is there any sort of performance overhead to choosing a CSS var instead of currentColor?

      I’m going to say with fairly strong confidence: No.

      Unless you’ve got some extremely major DOM weight and CSS usage situation going on, you don’t need to be concerning yourself with custom property (or currentColor) usage at all.

Leave a Reply to Chris Coyier Cancel reply

Your email address will not be published. Required fields are marked *

Did you know?

Frontend Masters Donates to open source projects. $363,806 contributed to date.