DEV Community

Discussion on: Use `currentColor` to Keep CSS DRY and Component Colors Flexible

Collapse
 
mzaini30 profile image
Zen

currentColor native CSS?

Collapse
 
taufik_nurrohman profile image
Taufik Nurrohman • Edited

AFAIK, currentColor was come from fill attribute value in SVG to tell that the SVG color must inherit to the surrounding text color. Normally, we use style="color: inherit;" for generic HTML elements. And for borders, without specifying border color, its color should inherit to the text color automatically. Example:

html {
  border: 0 solid green;
}

body {
  color: red;
  border: 5px solid; /* a red border */
  border-color: inherit; /* a green border */
}

stackoverflow.com/a/13002311/1163000

Update: It becomes standard in CSS3 due to the SVG spec β†’ w3.org/TR/css-color-3/#currentcolor πŸ‘

Collapse
 
mzaini30 profile image
Zen

Iya sih. Aku baru denger juga. Yang aku tau ya inherit. Tapi kayaknya pemakaiannya berbeda. Mungkin ya.

Thread Thread
 
5t3ph profile image
Stephanie Eckles

It is standard and has terrific browser support, clear back to IE9!

caniuse.com/#feat=currentcolor

The power is in using it for additional CSS properties beyond border color or SVG fill πŸ‘πŸ» It can even be used in gradients.

Thread Thread
 
taufik_nurrohman profile image
Taufik Nurrohman • Edited

But personally, I would prefer current-color or currentcolor just so that it would match to the CSS naming convention πŸ˜ƒ

I hope this value becomes case insensitive in the future. Same hope for viewBox attribute in SVG. I would like to see it as view-box or viewbox.