attr()
Retrieves the value of an attribute from an element to use directly in CSS. The classic use is with the content property in pseudo-elements; using attr() with typed values on other properties is a newer experimental extension.
Syntax
/* Usage Example */
a[data-tooltip]::before {
/* Displays the text from the data-tooltip attribute */
content: attr(data-tooltip);
position: absolute;
}
attr() Browser support
Widely available
Since
2015 99% global usage
This feature is well established and works across many devices and browser versions. It has been available across browsers since 2015.
4+
2+
3.1+
12+
Note: The attr() function can be used with any CSS property, but support for properties other than content is experimental. Use typed attr() on non-content properties as progressive enhancement only.