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.

Quick example

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

attr() Browser Support

Limited availability99% global usage

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Not ready for production without a fallback.

Interop 2026 focus area?Learn more →
ESC