# 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
(default) Interpret as a CSS string

color
interpret as a CSS color value

url
interpret as the URI part of a 'url()' expression

integer
interpret as a CSS integer. default = 0

number
interpret as a CSS number. default = 0.0

length
interpret as a CSS length. default = 0

angle
interpret as a CSS angle. default = 0

time
interpret as a CSS time. default = 0

frequency
interpret as a CSS frequency. default = 0

em
ex
px
mm
cm
in
pt
pc
deg
grad
rad
ms
s
Hz
kHz
interpret as a floating point value with the type suffixed as the unit. default = 0 with the relavant unit

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

Firefox | IE | Chrome | Opera | Safari

# Miscellaneous Information

Defined In: | CSS2.1