<uri>

  • Revision slug: Web/CSS/uri
  • Revision title: uri
  • Revision id: 394557
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment Adding note regarding https://bugzilla.mozilla.org/show_bug.cgi?id=752230Moved From CSS/uri to Web/CSS/uri

Revision Content

{{ CssRef() }}

Summary

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 {{ Cssxref("background-image") }}, {{ Cssxref("cursor") }}, {{ Cssxref("@font-face") }}, {{ cssxref("list-style") }} etc.  

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://mysite.example.com/mycursor.png")

 <a_css_property>:  url(http://mysite.example.com/mycursor.png)

Note: Control characters above 0x7e are no longer allowed in unquoted url() notation starting in Firefox 15. See {{Bug(752230)}} for more details.

Examples

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

Specifications

Specification Status Comment
{{ SpecName('CSS3 Values', '#urls', '<url>') }} {{ Spec2('CSS3 Values') }} No significant change from CSS Level 2 (Revision 1)
{{ Specname('CSS2.1', 'syndata.html#uri', '<uri>') }} {{ Spec2('CSS2.1') }} No significant change fromm CSS Level 1
{{ SpecName('CSS1', '#url', '<url>') }} {{ Spec2('CSS1') }}  

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 1.0 1.0 (1.0) 3.0 3.5 1.0 (85)
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support 1.0 1.0 (3.5) yes yes 1.0

See also

  • CSS Data Types : {{ CSSDataTypes() }}

Revision Source

<p>{{ CssRef() }}</p>
<h2 id="Summary">Summary</h2>
<p>The <code>&lt;url&gt;</code> <a href="/en/CSS" title="CSS">CSS</a> data type denotes a pointer to a resource. It has no proper syntax and can only be expressed through the <code>url()</code> functional notation.</p>
<div class="note">
  <strong>URI or URL?</strong><br />
  <br />
  There is a difference between a <a class="external" href="http://en.wikipedia.org/wiki/Uniform_Resource_Identifier" title="http://en.wikipedia.org/wiki/Uniform_Resource_Identifier">URI</a> and a <a class="external" href="http://en.wikipedia.org/wiki/Uniform_Resource_Locator" title="http://en.wikipedia.org/wiki/Uniform_Resource_Locator">URL</a>. 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 <a class="external" href="http://en.wikipedia.org/wiki/Uniform_Resource_Name" title="http://en.wikipedia.org/wiki/Uniform_Resource_Name">URN</a>, of a resource.<br />
  <br />
  In CSS Level 1, the <code>url()</code> functional notation was introduced to describe... URL, i.e. locations (a <code>&lt;url&gt;</code> CSS data type, though it wasn't explicitly defined that way).<br />
  <br />
  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 <code>url()</code> was used to create a <code>&lt;uri&gt;</code> CSS data type. Not only was this confusing, but URN are almost never used in the CSS usual case.<br />
  <br />
  To fix this, CSS Level 3 came back to the initial definition, this time explicitly defined. The functional notation <code>url() </code>denotes a <code>&lt;url&gt;</code> CSS data type and no more the more generic <code>&lt;uri&gt;</code> CSS data type.<br />
  <br />
  Remark that these semantic details doesn't change much for a web author, or the implementation details of the data type.</div>
<p>Many <a href="/en/CSS_Reference" title="en/CSS_Reference">CSS properties</a> take a URL as value, such as {{ Cssxref("background-image") }}, {{ Cssxref("cursor") }}, {{ Cssxref("@font-face") }}, {{ cssxref("list-style") }} etc.&nbsp;&nbsp;</p>
<h2 id="The_url()_functional_notation">The url() functional notation</h2>
<p>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).</p>
<h2 id="Syntax">Syntax</h2>
<pre>
 &lt;a_css_property&gt;:  url("http://mysite.example.com/mycursor.png")

 &lt;a_css_property&gt;:  url(http://mysite.example.com/mycursor.png)
</pre>
<div class="note">
  <p><strong>Note:</strong> Control characters above <span id="summary_alias_container"><span id="short_desc_nonedit_display">0x7e are no longer allowed in unquoted url() notation starting in Firefox 15. See</span></span> {{Bug(752230)}} for more details.</p>
</div>
<h2 id="Examples">Examples</h2>
<pre>
.topbanner { background: url("topbanner.png") #00D no-repeat fixed; }
</pre>
<pre>
ul { list-style: square url(http://www.example.com/redball.png) }
</pre>
<h2 id="Specifications" name="Specifications">Specifications</h2>
<table class="standard-table">
  <thead>
    <tr>
      <th scope="col">Specification</th>
      <th scope="col">Status</th>
      <th scope="col">Comment</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>{{ SpecName('CSS3 Values', '#urls', '&lt;url&gt;') }}</td>
      <td>{{ Spec2('CSS3 Values') }}</td>
      <td>No significant change from CSS Level 2 (Revision 1)</td>
    </tr>
    <tr style="vertical-align: top;">
      <td style="vertical-align: top;">{{ Specname('CSS2.1', 'syndata.html#uri', '&lt;uri&gt;') }}</td>
      <td style="vertical-align: top;">{{ Spec2('CSS2.1') }}</td>
      <td style="vertical-align: top;">No significant change fromm CSS Level 1</td>
    </tr>
    <tr>
      <td style="vertical-align: top;">{{ SpecName('CSS1', '#url', '&lt;url&gt;') }}</td>
      <td style="vertical-align: top;">{{ Spec2('CSS1') }}</td>
      <td style="vertical-align: top;">&nbsp;</td>
    </tr>
  </tbody>
</table>
<h2 id="Browser_Compatibility" name="Browser_Compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari (WebKit)</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>1.0</td>
        <td>1.0 (1.0)</td>
        <td>3.0</td>
        <td>3.5</td>
        <td>1.0 (85)</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Android</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>IE&nbsp;Phone</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>1.0</td>
        <td>1.0 (3.5)</td>
        <td>yes</td>
        <td>yes</td>
        <td>1.0</td>
      </tr>
    </tbody>
  </table>
</div>
<h2 id="See_also">See also</h2>
<ul>
  <li>CSS Data Types : {{ CSSDataTypes() }}</li>
</ul>
Revert to this revision