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.

/* Usage Example */
a[data-tooltip]::before {
  /* Displays the text from the data-tooltip attribute */
  content: attr(data-tooltip);
  position: absolute;
}

This comparison shows how attr() works in a real project. View snippet →

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+
Interop 2026 focus area ? Learn more →

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.

Kinsta

Your first month is free

Managed WordPress hosting for faster sites.

Learn more

New CSS drops.

Join 600+ readers who've survived clearfix hacks.

ESC