Description
The attr() function returns the value of the specified attribute.
This function has the form:
attr(attribute [',' <type> [ ',' <value> ]])
In CSS 2.1, the attr function only returns a string and can only be used with the content CSS property.
In CSS 3, functionality was expanded but is still very limited and varies widely between browsers. For example, IE8 and later can only take one argument.
Arguments
Name | Description |
---|---|
attribute | Specifies the attribute name. An optional namespace can be specifed separated by '|' |
type |
(optional) Specifies how to interpret the attribute. Valid values include:
string
color
url
integer
number
length
angle
time
frequency
em |
value | (optional) Specifies a valid CSS value |
Examples
This example shows how to set a width based upon a length:
width: attr(length);
Browser Support
Chrome | Firefox | IE | Safari | Opera |
---|---|---|---|---|
Miscellaneous Information
Defined In: | CSS2.1 |
---|