CSS attr() Function
Example
The following example inserts the value of the href attribute in parenthesis after each <a> element:
a:after {
content: " (" attr(href) ")";
}
Try it Yourself »
Definition and Usage
The CSS attr()
function returns the value of an attribute of the selected elements.
Version: | CSS2 |
---|
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 | 119 | No | No |
fallback | No | No | No | 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 |