Revision 238113 of background

  • Revision slug: CSS/background
  • Revision title: background
  • Revision id: 238113
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment

Revision Content

{{ CSSRef() }}

Summary

The background CSS property is a shorthand for setting the individual background values in a single place in the style sheet. background can be used to set the values for one or more of: {{ Cssxref("background-color") }}, {{ Cssxref("background-image") }}, {{ Cssxref("background-position") }}, {{ Cssxref("background-repeat") }}, {{ cssxref("background-size") }}, and {{ Cssxref("background-attachment") }}.

The background shorthand property assigns explicit given values and sets missing properties to their initial values.

  • {{ Xref_cssinitial() }}: transparent || none || repeat || scroll || 0% 0%
  • Applies to: all elements
  • {{ Xref_cssinherited() }}: no
  • Percentages: allowed on {{ Cssxref("background-position") }} only
  • Media: {{ Xref_cssvisual() }}
  • {{ Xref_csscomputed() }}: see individual properties

Syntax

background:  [<bg-layer>, ]* <final-bg-layer>

where:

<bg-layer>
[ <background-image> || <background-position> [ / <background-size> ]? || <background-repeat> || <background-attachment> || <background-clip> ]
|  {{ Cssxref("inherit") }}
<final-bg-layer>
[ <background-color> || <background-image> || <background-position> [ / <background-size> ]? || <background-repeat> || <background-attachment> || <background-clip> ]
|  {{ Cssxref("inherit") }}
Note: The background-color can only be defined on the last background, as there is only one background color for the whole element.

Values

One or more of the following, in any order:

<background-color>
See {{ cssxref("background-color") }}
<background-image>
See {{ Cssxref("background-image") }}
<background-position>
See {{ cssxref("background-position") }}
<background-size>
See {{ cssxref("background-size") }}
<background-repeat>
See {{ cssxref("background-repeat") }}
<background-attachment>
See {{ cssxref("background-attachment") }}
<background-clip>
See {{ cssxref("background-clip") }}

Examples

{{ CSSLiveSample('background.html') }}

body { background: red; }

.topbanner { background: url("topbanner.png") #00D repeat-y fixed; }

Specifications

Specification Status Comment
CSS Backgrounds and Borders Module Level 3 {{ Spec2('CSS3 Backgrounds') }} The shorthand property has been extended to support multiple backgrounds and the new {{ cssxref("background-size") }} and {{ cssxref("background-clip") }} properties.
CSS 2.1 {{ Spec2('CSS2.1') }} No significant changes
CSS 1 {{ Spec2('CSS1') }}  

Browser compatibility

{{ CompatibilityTable() }}

Feature Firefox (Gecko) Chrome Internet Explorer Opera Safari
Basic support {{ CompatGeckoDesktop("1.0") }} 1.0 4.0 3.5 1.0
Multiple backgrounds {{ CompatGeckoDesktop("1.9.2") }} 1.0 9.0 10.5 1.3
SVG image as background {{ CompatGeckoDesktop("2.0") }} {{ CompatVersionUnknown() }} 9.0 # {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }}
Feature Firefox Mobile (Gecko) Android IE Phone Opera Mobile Safari Mobile
Basic support {{ CompatGeckoMobile("1.9.2") }} 2.1 {{ CompatUnknown() }} 10.0 3.2
Multiple backgrounds {{ CompatGeckoMobile("1.9.2") }} 2.1 {{ CompatUnknown() }} 10.0 3.2
SVG image as background {{ CompatGeckoMobile("2.0") }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}

See also

{{ languages( { "de": "de/CSS/background", "es": "es/CSS/background", "fr": "fr/CSS/background", "it": "it/CSS/background", "ja": "ja/CSS/background", "ko": "ko/CSS/background", "pl": "pl/CSS/background", "pt": "pt/CSS/background", "zh-cn": "cn/CSS/background" } ) }}

Revision Source

<p>{{ CSSRef() }}</p>
<h2 id="Summary">Summary</h2>
<p>The<code> background </code>CSS property is a shorthand for setting the individual background values in a single place in the style sheet.<code> background </code>can be used to set the values for one or more of: {{ Cssxref("background-color") }}, {{ Cssxref("background-image") }}, {{ Cssxref("background-position") }}, {{ Cssxref("background-repeat") }}, {{ cssxref("background-size") }}, and {{ Cssxref("background-attachment") }}.</p>
<p>The<code> <span class="propinst-background">background</span> </code>shorthand property assigns explicit given values and sets missing properties to their initial values.</p>
<ul class="cssprop">
  <li><dfn>{{ Xref_cssinitial() }}:</dfn><code> transparent || none || repeat || scroll || 0% 0%</code></li>
  <li><dfn>Applies to:</dfn> all elements</li>
  <li><dfn>{{ Xref_cssinherited() }}:</dfn> no</li>
  <li><dfn>Percentages:</dfn> allowed on {{ Cssxref("background-position") }} only</li>
  <li><dfn>Media:</dfn> {{ Xref_cssvisual() }}</li>
  <li><dfn>{{ Xref_csscomputed() }}:</dfn> see individual properties</li>
</ul>
<h2 id="Syntax">Syntax</h2>
<pre class="eval syntaxbox">background:  [&lt;bg-layer&gt;, ]* &lt;final-bg-layer&gt;
</pre>
<p>where:</p>
<dl>
  <dt>
    &lt;bg-layer&gt;</dt>
  <dd>
    <code>[ &lt;background-image&gt; || &lt;background-position&gt; [ / &lt;background-size&gt; ]? || &lt;background-repeat&gt; || &lt;background-attachment&gt; || &lt;background-clip&gt; ]<br>
    |  {{ Cssxref("inherit") }}</code></dd>
  <dt>
    &lt;final-bg-layer&gt;</dt>
  <dd>
    <code>[ &lt;background-color&gt; || &lt;background-image&gt; || &lt;background-position&gt; [ / &lt;background-size&gt; ]? || &lt;background-repeat&gt; || &lt;background-attachment&gt; || &lt;background-clip&gt; ]<br>
    |  {{ Cssxref("inherit") }}</code></dd>
</dl>
<div class="note">
  <strong>Note:</strong> The background-color can only be defined on the last background, as there is only one background color for the whole element.</div>
<h2 id="Values">Values</h2>
<p>One or more of the following, in any order:</p>
<dl>
  <dt>
    &lt;background-color&gt;</dt>
  <dd>
    See {{ cssxref("background-color") }}</dd>
  <dt>
    &lt;background-image&gt;</dt>
  <dd>
    See {{ Cssxref("background-image") }}</dd>
  <dt>
    &lt;background-position&gt;</dt>
  <dd>
    See {{ cssxref("background-position") }}</dd>
  <dt>
    &lt;background-size&gt;</dt>
  <dd>
    See {{ cssxref("background-size") }}</dd>
  <dt>
    &lt;background-repeat&gt;</dt>
  <dd>
    See {{ cssxref("background-repeat") }}</dd>
  <dt>
    &lt;background-attachment&gt;</dt>
  <dd>
    See {{ cssxref("background-attachment") }}</dd>
  <dt>
    &lt;background-clip&gt;</dt>
  <dd>
    See {{ cssxref("background-clip") }}</dd>
</dl>
<h2 id="Examples">Examples</h2>
<p>{{ CSSLiveSample('background.html') }}</p>
<pre>body { background: red; }

.topbanner { background: url("topbanner.png") #00D repeat-y fixed; }
</pre>
<h2 id="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><a class="external" href="http://www.w3.org/TR/css3-background/" title="http://www.w3.org/TR/css3-background/">CSS Backgrounds and Borders Module Level 3</a></td>
      <td>{{ Spec2('CSS3 Backgrounds') }}</td>
      <td>The shorthand property has been extended to support multiple backgrounds and the new {{ cssxref("background-size") }} and {{ cssxref("background-clip") }} properties.</td>
    </tr>
    <tr>
      <td><a class="external" href="http://www.w3.org/TR/CSS21/colors.html#propdef-background">CSS 2.1</a></td>
      <td>{{ Spec2('CSS2.1') }}</td>
      <td>No significant changes</td>
    </tr>
    <tr>
      <td><a class="external" href="http://www.w3.org/TR/CSS1/#background" title="http://www.w3.org/TR/CSS1/#background">CSS 1</a></td>
      <td>{{ Spec2('CSS1') }}</td>
      <td> </td>
    </tr>
  </tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Firefox (Gecko)</th>
        <th>Chrome</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{ CompatGeckoDesktop("1.0") }}</td>
        <td>1.0</td>
        <td>4.0</td>
        <td>3.5</td>
        <td>1.0</td>
      </tr>
      <tr>
        <td>Multiple backgrounds</td>
        <td>{{ CompatGeckoDesktop("1.9.2") }}</td>
        <td>1.0</td>
        <td>9.0</td>
        <td>10.5</td>
        <td>1.3</td>
      </tr>
      <tr>
        <td>SVG image as background</td>
        <td>{{ CompatGeckoDesktop("2.0") }}</td>
        <td>{{ CompatVersionUnknown() }}</td>
        <td>9.0<a class="external" href="http://msdn.microsoft.com/en-us/ie/hh393506#_CSS3_BG_Borders" title="http://msdn.microsoft.com/en-us/ie/hh393506#_CSS3_BG_Borders"> #</a></td>
        <td>{{ CompatVersionUnknown() }}</td>
        <td>{{ CompatVersionUnknown() }}</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>Android</th>
        <th>IE Phone</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{ CompatGeckoMobile("1.9.2") }}</td>
        <td>2.1</td>
        <td>{{ CompatUnknown() }}</td>
        <td>10.0</td>
        <td>3.2</td>
      </tr>
      <tr>
        <td>Multiple backgrounds</td>
        <td>{{ CompatGeckoMobile("1.9.2") }}</td>
        <td>2.1</td>
        <td>{{ CompatUnknown() }}</td>
        <td>10.0</td>
        <td>3.2</td>
      </tr>
      <tr>
        <td>SVG image as background</td>
        <td>{{ CompatGeckoMobile("2.0") }}</td>
        <td>{{ CompatUnknown() }}</td>
        <td>{{ CompatUnknown() }}</td>
        <td>{{ CompatUnknown() }}</td>
        <td>{{ CompatUnknown() }}</td>
      </tr>
    </tbody>
  </table>
</div>
<h2 id="See_also">See also</h2>
<ul>
  <li>{{ CSS_Reference:Background() }}</li>
  <li>{{ cssxref("-moz-background-size") }}, {{ cssxref("-moz-background-inline-policy") }}</li>
  <li><a href="/en/CSS/Using_CSS_gradients" title="en/Using gradients">Using gradients</a></li>
  <li><a href="/en/CSS/Multiple_backgrounds" title="en/CSS/Multiple backgrounds">Multiple backgrounds</a></li>
</ul>
{{ languages( { "de": "de/CSS/background", "es": "es/CSS/background", "fr": "fr/CSS/background", "it": "it/CSS/background", "ja": "ja/CSS/background", "ko": "ko/CSS/background", "pl": "pl/CSS/background", "pt": "pt/CSS/background", "zh-cn": "cn/CSS/background" } ) }}
Revert to this revision