background-attachment

  • Revision slug: CSS/background-attachment
  • Revision title: background-attachment
  • Revision id: 21284
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment one or more formatting changes

Revision Content

{{ CSSRef() }}

Summary

If a {{ Cssxref("background-image") }} is specified, the background-attachment CSS property determines whether that image's position is fixed within the viewport, or scrolls along with its containing block.

<style type="text/css"></style>
  • {{ Xref_cssinitial() }}: scroll
  • Applies to: all elements
  • {{ Xref_cssinherited() }}: no
  • Media: {{ Xref_cssvisual() }}
  • {{ Xref_csscomputed() }}: as specified

Syntax

background-attachment:  attachment[, attachment]*

where:

attachment
Is a keyword that can have one of the following values:
  • scroll, meaning that the background image will scroll within the viewport along with the block the image is contained within.
  • fixed, meaning that the background image will not scroll with its containing element, instead remaining stationary within the viewport.
  • local, meaning that the background image will not scroll with its containing element, but will scroll when the element's content scrolls: it is fixed regarding the element's content.

Examples

{{ CSSRefExampleLink("background-attachment") }}

body {
	background-image: url("images/cartooncat.png");
	background-attachment: fixed;
}

Multiple background image support

This property supports multiple background images. You can specify a different <attachment> for each background, separated by commas:

body {
  background-image: url("img1.png"), url("img2.png");
  background-attachment: scroll, fixed;
} 

Each image is matched with the corresponding attachment type, from first specified to last.

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 local value.
CSS 2.1 {{ Spec2('CSS2.1') }}  
CSS 1 {{ Spec2('CSS1') }}  

Browser Compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 {{ CompatGeckoDesktop("1.0") }} 4.0 3.5 1.0
Multiple backgrounds 1.0 {{ CompatGeckoDesktop("1.9.2") }} 9.0 10.5 1.3
local 4.0 {{ CompatNo() }} 9.0 10.5 5.0
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support 2.1 {{ CompatGeckoMobile("1.9.2") }} {{ CompatUnknown() }} 10.0 3.2
Multiple backgrounds 2.1 {{ CompatGeckoMobile("1.9.2") }} {{ CompatUnknown() }} 10.0 3.2
local {{ CompatUnknown() }} {{ CompatNo() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}

See also

{{ languages( { "de": "de/CSS/background-attachment", "es": "es/CSS/background-attachment", "fr": "fr/CSS/background-attachment", "it": "it/CSS/background-attachment", "pl": "pl/CSS/background-attachment" } ) }}

Revision Source

<p>{{ CSSRef() }}</p>
<h2>Summary</h2>
<p>If a {{ Cssxref("background-image") }} is specified, the <code>background-attachment</code> <a href="/en/CSS" title="CSS">CSS</a> property determines whether that image's position is fixed within the viewport, or scrolls along with its containing block.</p>
<nobr>
<style type="text/css"><![CDATA[.cssprop {
  display:table;
  padding: 0.4em;
  border-left:0.15em solid;
  background-color:#eeeeff
}
.cssprop li {
 display:table-row;
 padding: 3px;
 margin:0;
}
.cssprop li dfn {
  display:table-cell;
  padding: 0 5px;
  border-bottom: none;
  cursor:inherit;
}

]]></style>
<ul class="cssprop"> <li><dfn>{{ Xref_cssinitial() }}:</dfn> <code>scroll</code></li> <li><dfn>Applies to:</dfn> all elements</li> <li><dfn>{{ Xref_cssinherited() }}:</dfn> no</li> <li><dfn>Media:</dfn> {{ Xref_cssvisual() }}</li> <li><dfn>{{ Xref_csscomputed() }}:</dfn> as specified</li>
</ul></nobr><h2>Syntax</h2>
<pre class="syntaxbox">background-attachment:  <em>attachment</em>[, <em>attachment</em>]*
</pre>
<p>where:</p>
<dl> <dt><em>attachment</em></dt> <dd>Is a <em>keyword</em> that can have one of the following values: <ul> <li><code>scroll</code>, meaning that the background image will scroll within the viewport along with the block the image is contained within.</li> <li><code>fixed</code>, meaning that the background image will not scroll with its containing element, instead remaining stationary within the viewport.</li> <li><code>local</code>, meaning that the background image will not scroll with its containing element, but will scroll when the element's content scrolls: it is fixed regarding the element's content.</li> </ul> </dd>
</dl>
<h2>Examples</h2>
<p>{{ CSSRefExampleLink("background-attachment") }}</p>
<pre>body {
	background-image: url("images/cartooncat.png");
	background-attachment: fixed;
}
</pre>
<h4>Multiple background image support</h4>
<p>This property supports multiple background images. You can specify a different <code>&lt;attachment&gt;</code> for each background, separated by commas:</p>
<pre>body {
  background-image: url("img1.png"), url("img2.png");
  background-attachment: scroll, fixed;
} 
</pre>
<p>Each image is matched with the corresponding attachment type, from first specified to last.</p>
<h2>Specifications</h2>
<table class="standard-table"> <thead> <tr style="background-color: rgb(255, 204, 255);"> <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/#the-background-attachment" title="http://www.w3.org/TR/css3-background/#the-background-attachment">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 <code>local</code> value.</td> </tr> <tr> <td><a class="external" href="http://www.w3.org/TR/CSS21/colors.html#propdef-background-attachment" title="http://www.w3.org/TR/CSS21/colors.html#propdef-background-attachment">CSS 2.1</a></td> <td>{{ Spec2('CSS2.1') }}</td> <td> </td> </tr> <tr> <td><a class="external" href="http://www.w3.org/TR/CSS1/#background-attachment" title="http://www.w3.org/TR/CSS1/#background-attachment">CSS 1</a></td> <td>{{ Spec2('CSS1') }}</td> <td> </td> </tr> </tbody>
</table>
<h2 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</th> </tr> <tr> <td>Basic support</td> <td>1.0</td> <td>{{ CompatGeckoDesktop("1.0") }}</td> <td>4.0</td> <td>3.5</td> <td>1.0</td> </tr> <tr> <td>Multiple backgrounds</td> <td>1.0</td> <td>{{ CompatGeckoDesktop("1.9.2") }}</td> <td>9.0</td> <td>10.5</td> <td>1.3</td> </tr> <tr> <td><code>local</code></td> <td>4.0</td> <td>{{ CompatNo() }} <a class="link-https" href="https://bugzilla.mozilla.org/show_bug.cgi?id=483446" title="https://bugzilla.mozilla.org/show_bug.cgi?id=483446"></a></td> <td>9.0</td> <td>10.5</td> <td>5.0</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 Phone</th> <th>Opera Mobile</th> <th>Safari Mobile</th> </tr> <tr> <td>Basic support</td> <td>2.1</td> <td>{{ CompatGeckoMobile("1.9.2") }}</td> <td>{{ CompatUnknown() }}</td> <td>10.0</td> <td>3.2</td> </tr> <tr> <td>Multiple backgrounds</td> <td>2.1</td> <td>{{ CompatGeckoMobile("1.9.2") }}</td> <td>{{ CompatUnknown() }}</td> <td>10.0</td> <td>3.2</td> </tr> <tr> <td><code>local</code></td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatNo() }} <a class="link-https" href="https://bugzilla.mozilla.org/show_bug.cgi?id=483446" title="https://bugzilla.mozilla.org/show_bug.cgi?id=483446"></a></td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> </tr> </tbody> </table>
</div>
<h2>See also</h2>
<ul> <li>{{ CSS_Reference:Background() }}</li> <li><a href="/en/CSS/Multiple_backgrounds" title="en/CSS/Multiple backgrounds">Multiple backgrounds</a></li>
</ul>
<p class="script-jem">{{ languages( { "de": "de/CSS/background-attachment", "es": "es/CSS/background-attachment", "fr": "fr/CSS/background-attachment", "it": "it/CSS/background-attachment", "pl": "pl/CSS/background-attachment" } ) }}</p>
Revert to this revision