CSS attr() Function
The CSS attr() function returns the value of an attribute of the selected element.
Example
The following example inserts the value of the cite attribute in parenthesis after the <blockquote> element:
blockquote:after {
content: " (source: " attr(cite) ") ";
color: hotpink;
}
Try it Yourself »
Browser Support
The numbers in the table specify the first browser version that fully supports the function.
| Function | |||||
|---|---|---|---|---|---|
| attr() | 2 | 8 | 1 | 3.1 | 9 |
| type | No | No | No | No | No |
| fallback | No | No | 119 | No | No |
CSS Syntax
attr(attribute-name type fallback)
| Value | Description |
|---|---|
| attribute-name | Required. The name of the attribute of the HTML element(s) |
| type | Optional. The attribute values' type or its unit. Can be one of the
following:
|
| fallback | Optional. The value to be used if the attribute is missing or contains an invalid value |
| Version: | CSS2 |
|---|