{"id":8711,"date":"2011-03-17T05:38:43","date_gmt":"2011-03-17T12:38:43","guid":{"rendered":"http:\/\/css-tricks.com\/?p=8711"},"modified":"2022-06-09T10:15:16","modified_gmt":"2022-06-09T17:15:16","slug":"currentcolor","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/currentcolor\/","title":{"rendered":"currentcolor"},"content":{"rendered":"\n

CSS variables are always a hot topic when “the future of CSS” is discussed. They are actually coming<\/a> natively, but using them in production (without a CSS preprocessor<\/a> framework) is a long way off. However there is a feature that actually has some browser support now that has a CSS variable feel to it, and that’s the currentColor<\/code> value. <\/p>\n\n\n\n\n\n\n\n

It works like this:<\/p>\n\n\n\n

div { \n  color: red; \n  border: 5px solid currentcolor;\n  box-shadow: 0 0 5px solid currentcolor;\n}<\/code><\/pre>\n\n\n\n

I learned about this from a panel at SXSW 2011 on CSS3 with Stephanie<\/a> & Greg<\/a> Rewis, Estelle Weyl<\/a>, and Christopher Schmitt<\/a>. Googling it turned up Divya Manian’s article<\/a> who says:<\/p>\n\n\n\n

[…] you can use this value to indicate you want to use the value of color for other properties that accept a color value: borders, box shadows, outlines, or backgrounds.<\/p>

This value was first supported by Opera in 2009, since then, Firefox 3.5+, Chrome 1+, and Safari 4+.<\/p><\/blockquote>\n\n\n\n

Here’s the spec<\/a> and the Can I Use information<\/a>.<\/p>\n\n\n

It will follow the cascade<\/h3>\n\n\n
body { color: red; }\ndiv { border: 5px solid currentcolor; }<\/code><\/pre>\n\n\n

You can’t trick it.<\/h3>\n\n\n

Let’s say you wanted to exploit the variable quality to it, but then reset the color for the actual text… this won’t work:<\/p>\n\n\n\n

div {\n   color: red;\n      \n   border: 5px solid currentcolor;\n   box-shadow: 0 0 5px currentcolor; \n    \n   color: black;\n }<\/code><\/pre>\n\n\n\n

Everything will be black.<\/p>\n\n\n

Use cases<\/h3>\n\n\n