attr() CSS Function


The attr() CSS function returns the value of a property. That means that you can define content in your html markup using any custom property and then fetch the value using attr(). It only works on the content property at the moment, but support for other properties are currently in the experimental stage.


attr( <attr-name> <type-or-unit>? [ , <attr-fallback> ]? )


  • <attr-name>Is the name of an attribute on the HTML element referenced in the CSS.
  • <type-or-unit>Is a keyword representing either the type of the attribute's value, or its unit, as in HTML some attributes have implicit units. The following keywords are valid: <string>, <color>, <url>, <integer>, <number>, <angle>, <time>, <deg>, and also CSS units like em, ex, px, rem, vw, vh, vmin, vmax, mm, cm, in, pt, or pc
  • <attr-fallback>The value that will be used if the attribute is absent or the browser cannot receive it.


<p>The attr() Function</p> 
<a href="">CSSPortal</a>
a:before { 
content: attr(href) " -> ";
a {
text-decoration: none;

Browser Support

Explorer Edge Chrome Firefox Opera Safari
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung

Last updated by CSSPortal on: 1st December 2019