uri property CSS Reference



Definition and Usage

The <url> CSS data type denotes a pointer to a resource. It has no proper syntax and can only be expressed through the url() functional notation.

URI or URL?

There is a difference between a URI and a URL. A URL describes the location of the resource, the URI describes an id of the resource . A URI may be a location, a URL, or a name, a URN, of a resource.

In CSS Level 1, the url() functional notation was introduced to describe... URL, i.e. locations (a <url> CSS data type, though it wasn't explicitly defined that way).

In CSS Level 2, the same functional notation was extended to describe any URI, being a URL or URN. This led to the confusing fact that url() was used to create a <uri> CSS data type. Not only was this confusing, but URN are almost never used in the CSS usual case.

To fix this, CSS Level 3 came back to the initial definition, this time explicitly defined. The functional notation url() denotes a <url> CSS data type and no more the more generic <uri> CSS data type.

Remark that these semantic details doesn't change much for a web author, or the implementation details of the data type.

Many CSS properties take a URL as value, such as background-image, cursor, @font-face, list-style etc.  

The URI may be quoted by single or double quotes. Relative URIs are allowed and are relative to the URL of stylesheet (and not to the URL of the web page).

The url() functional notation

The URI may be quoted by single or double quotes. Relative URIs are allowed and are relative to the URL of stylesheet (and not to the URL of the web page).


Syntax

 <a_css_property>:  url("http://www.website.com/cursor.png")
 <a_css_property>:  url(http://www.website.com/cursor.png)

Note: Control characters above 0x7e are no longer allowed in unquoted url() notation starting in Firefox 15.


Examples

.topbanner { background: url("topbanner.png") #00D no-repeat fixed; }
ul { list-style: square url(http://www.example.com/ball.png) }

Compatibility

Desktop browsers

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 1.0 1.0 (1.0) 3.0 3.5 1.0 (85)

Mobile browsers

Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support 1.0 1.0 (3.5) yes yes 1.0

Relative articles