background-origin

  • Revision slug: Web/CSS/background-origin
  • Revision title: background-origin
  • Revision id: 490359
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment

Revision Content

{{CSSRef}}

Summary

The background-origin CSS property determines the background positioning area, that is the position of the origin of an image specified using the {{cssxref("background-image")}} CSS property.

Note that background-origin is ignored when {{Cssxref("background-attachment")}} is fixed.

If the value of this property is not set in a {{cssxref("background")}} shorthand property that is applied to the element after the background-origin CSS property, the value of this property is then reset to its initial value by the shorthand property.

{{cssbox("background-origin")}}

Syntax

Formal syntax: {{csssyntax("background-origin")}}
background-origin: border-box
background-origin: padding-box
background-origin: content-box

background-origin: inherit

Values

border-box
The background extends to the outside edge of the border (but underneath the border in z-ordering).
padding-box
No background is drawn below the border (background extends to the outside edge of the padding).
content-box
The background is painted within (clipped to) the content box.

Examples

 .example {
   border: 10px double;
   padding: 10px;
   background: url('image.jpg');
   background-position: center left;
   /* The background will be inside the padding */ 
   background-origin: content-box;
}
div {
  background-image: url('logo.jpg'), url('mainback.png');
  background-position: top right, 0px 0px;
  background-origin: content-box, padding-box;
}

Specifications

Specification Status Comment
{{SpecName('CSS3 Backgrounds', '#the-background-origin', 'background-origin')}} {{Spec2('CSS3 Backgrounds')}}  

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 [3] {{CompatGeckoDesktop("2.0")}} [1] 9.0 [2] 10.5 3.0 (522) [3]
content-box 1.0 [3] {{CompatGeckoDesktop("2.0")}} [1] 9.0 [2] {{CompatNo}} 3.0 (522) [3]
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
content-box {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

[1] Gecko supported, from version 1.1 to version 1.9.2, which corresponds to Firefox 1.0 to 3.6 included, a different, and prefixed, syntax: -moz-background-origin: padding | border.

[2] Internet Explorer up to version 7 behaves as if there was a background-origin: border-box; Internet Explorer 8 behaves as if it were background-origin: padding-box; which is the regular default value.

[3] Webkit also supports the prefixed version of this proprietary, and in that case, in addition to the current keywords, the alternative synonyms: padding, border, and content.

[4] Konqueror 3.5.4 supports -khtml-background-origin.

See also

  • {{CSS_Reference:Background}}

Revision Source

<div>
 {{CSSRef}}</div>
<h2 id="Summary">Summary</h2>
<p>The <code>background-origin</code> CSS property determines the background positioning area, that is the position of the origin of an image specified using the {{cssxref("background-image")}} CSS property.</p>
<p>Note that <code>background-origin</code> is ignored when {{Cssxref("background-attachment")}} is <code><code>fixed</code></code>.</p>
<div class="note">
 If the value of this property is not set in a {{cssxref("background")}} shorthand property that is applied to the element after the <code>background-origin</code> CSS property, the value of this property is then reset to its initial value by the shorthand property.</div>
<p>{{cssbox("background-origin")}}</p>
<h2 id="Syntax">Syntax</h2>
<pre class="twopartsyntaxbox">
<a href="/en-US/docs/CSS/Value_definition_syntax" title="CSS/Value_definition_syntax">Formal syntax</a>: {{csssyntax("background-origin")}}</pre>
<pre>
background-origin: border-box
background-origin: padding-box
background-origin: content-box

background-origin: inherit
</pre>
<h3 id="Values">Values</h3>
<dl>
 <dt>
  <code>border-box</code></dt>
 <dd>
  The background extends to the outside edge of the border (but underneath the border in z-ordering).</dd>
 <dt>
  <code>padding-box</code></dt>
 <dd>
  No background is drawn below the border (background extends to the outside edge of the padding).</dd>
 <dt>
  <code>content-box</code></dt>
 <dd>
  The background is painted within (clipped to) the content box.</dd>
</dl>
<h2 id="Examples">Examples</h2>
<pre class="brush:css; highlight:[7];">
 .example {
   border: 10px double;
   padding: 10px;
   background: url('image.jpg');
   background-position: center left;
   /* The background will be inside the padding */ 
   background-origin: content-box;
}
</pre>
<pre class="brush:css; highlight:[4];">
div {
  background-image:&nbsp;url('logo.jpg'), url('mainback.png');
  background-position:&nbsp;top right, 0px 0px;
  background-origin:&nbsp;content-box, padding-box;
}</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>{{SpecName('CSS3 Backgrounds', '#the-background-origin', 'background-origin')}}</td>
   <td>{{Spec2('CSS3 Backgrounds')}}</td>
   <td>&nbsp;</td>
  </tr>
 </tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<div>
 {{CompatibilityTable}}</div>
<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 [3]</td>
    <td>{{CompatGeckoDesktop("2.0")}} [1]</td>
    <td>9.0 [2]</td>
    <td>10.5</td>
    <td>3.0 (522) [3]</td>
   </tr>
   <tr>
    <td><code>content-box</code></td>
    <td>1.0 [3]</td>
    <td>{{CompatGeckoDesktop("2.0")}} [1]</td>
    <td>9.0 [2]</td>
    <td>{{CompatNo}}</td>
    <td>3.0 (522) [3]</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>{{CompatUnknown}}</td>
    <td>{{CompatUnknown}}</td>
    <td>{{CompatUnknown}}</td>
    <td>{{CompatUnknown}}</td>
    <td>{{CompatUnknown}}</td>
   </tr>
   <tr>
    <td><code>content-box</code></td>
    <td>{{CompatUnknown}}</td>
    <td>{{CompatUnknown}}</td>
    <td>{{CompatUnknown}}</td>
    <td>{{CompatUnknown}}</td>
    <td>{{CompatUnknown}}</td>
   </tr>
  </tbody>
 </table>
</div>
<p>[1] Gecko supported, from version 1.1 to version 1.9.2, which corresponds to Firefox 1.0 to 3.6 included, a different, and prefixed, syntax: <code>-moz-background-origin: padding | border</code>.</p>
<p>[2] Internet Explorer up to version 7 behaves as if there was a <code>background-origin: border-box;</code> Internet Explorer 8 behaves as if it were <code>background-origin: padding-box;</code> which is the regular default value.</p>
<p>[3] Webkit also supports the prefixed version of this proprietary, and in that case, in addition to the current keywords, the alternative synonyms: <code>padding</code>, <code>border</code>, and <code>content</code>.</p>
<p>[4] Konqueror 3.5.4 supports<code> -khtml-background-origin</code>.</p>
<h2 id="See_also">See also</h2>
<ul>
 <li>{{CSS_Reference:Background}}</li>
</ul>
Revert to this revision