- Description
Attr() returns the value of an HTML attribute to be used as a value in stylesheet.
This was first introduced in CSS2.1 with the syntax:
attr( attribute-name )
could only be used with content and only returned string values.In CSS3 the syntax changed to:
attr( attribute-name, [ <type> ], [ <value> ] )
it can be used with all properties and many types can be returned.Type can be any of: 'string', 'color', number', 'integer', 'url', ‘length’ ‘angle’ ‘time’ ‘frequency’, ‘em’ ‘ex’ ‘px’ ‘rem’ ‘vw’ ‘vh’ ‘vmin’ ‘mm’ ‘cm’ ‘in’ ‘pt’ ‘pc’ ‘deg’ ‘grad’ ‘rad’ ‘ms’ ‘s’ ‘Hz’ ‘kHz’ ‘%’.
Value is a fallback used when no value is returned.
See Also:
- Live Example
- Play with the code in the textarea below.
- Values
- attr( attribute-name, [ <type> ], [ <value> ] )
- Introduced in CSS version
- 2.1
- Applies to elements
- All properties
- Inherited
- N/A
- Browser Support
Browsers IE Firefox Safari Opera Chrome Versions 8 1.7 3.1 9 2
Belongs to:
See the full list CSS properties and browser support: CSS Properties