background-repeat

  • Revision slug: CSS/background-repeat
  • Revision title: background-repeat
  • Revision id: 299837
  • Created:
  • Creator: ethertank
  • Is current revision? No
  • Comment

Revision Content

{{ CSSRef() }}

Summary

The background-repeat CSS property defines how background images are repeated. A background image can be repeated along the horizontal axis, the vertical axis, both, or not repeated at all. When the repetition of the image tiles doesn't let them exactly cover the background, the way adjustments are done can be controlled by the author: by default, the last image is clipped, but the different tiles can instead be re-sized, or space can be inserted between the tiles.

Note: If the value of this property is not set in a {{ cssxref("background") }} shorthand property that is applied to the element after the background-repeat CSS property, the value of this property is then reset to its initial value by the shorthand property.
  • {{Xref_cssinitial()}} repeat
  • Applies to all elements
  • {{Xref_cssinherited()}} no
  • Media {{ Xref_cssvisual() }}
  • {{Xref_csscomputed()}} as specified

Syntax

background-repeat: repeat-style[, repeat-style]*

where:

repeat-style
Is following either the one-value syntax — and in that case the values are shorthand for ther two-value equivalent:
repeat-x is the equivalent of repeat no-repeat
repeat-y is the equivalent of no-repeat repeat
repeat is the equivalent of repeat repeat
space is the equivalent of space space
round is the equivalent of round round
no-repeat is the equivalent of no-repeat no-repeat
Or the two-value syntax where the first value represents the horizontal behavior of the repetition and the second value the vertical behavior:

repeat The image is repeated in the given direction as much as needed to cover the whole background image painting area. The last image may be clipped if the whole thing won't fit in the remaining area.
space The image is repeated in the given direction as much as needed to cover most of the background image painting area, without clipping an image. The remaining non-covered space is spaced out evenly between the images. The first and last images touches the edge of the element. The value of the {{ cssxref("background-position") }} CSS property is ignored for the concerned direction, except if one single image is greater than the background image painting area, which is the only case where an image can be clipped when the space value is used.
round The image is repeated in the given direction as much as needed to cover most of the background image painting area, without clipping an image. If it doesn't cover exactly the area, the tiles are resized in that direction in order to match it.
no-repeat The image is not repeated (and hence the background image painting area will not necessarily been entirely covered). The position of the non-repeated background image is defined by the {{ cssxref("background-position") }} CSS property.

Examples

{{ CSSLiveSample("background-repeat") }}

.exampleone {
  background-image: url("logo.png");
  background-repeat: repeat-x;
}

.exampletwo {
  background-image: url("logo.png");
  background-repeat: no-repeat;
}

.examplethree {
  background-image: url("img1.png"), url("img2.png");
  background-repeat: repeat-x, repeat-y;
} 

Each image is matched with the corresponding repeat style, from first specified to last.

Specifications

Specification Status Comment
{{ SpecName('CSS3 Backgrounds', '#the-background-repeat', 'background-repeat') }} {{ Spec2('CSS3 Backgrounds') }} Added support for multiple backgrounds images, the two-value syntax allowing distinct repetition behavior for the horizontal and vertical directions, the space and round keywords, and for backgrounds on inline-level element by defining precisely the background painting area.
{{ SpecName('CSS2.1', 'colors.html#propdef-background-repeat', 'background-repeat') }} {{ Spec2('CSS2.1') }} No significant changes
{{ SpecName('CSS1', '#background-repeat', 'background-repeat') }} {{ 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 (85)
Multiple backgrounds 1.0 {{ CompatGeckoDesktop("1.9.2") }} 9.0 10.5 1.3 (312)
Different values for X & Y directions (two-value syntax) {{ CompatVersionUnknown() }} {{ CompatGeckoDesktop("13.0") }} {{ bug("548375") }} 9.0 {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }}
round and space keywords {{ CompatNo() }} {{ CompatNo() }} {{ bug("548372") }} 9.0 10.5 {{ CompatNo() }}
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}
Multiple backgrounds {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}
Different values for X & Y directions (two-value syntax) {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}
round and space keywords {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}

See also

Revision Source

<p>{{ CSSRef() }}</p>
<h2 id="Summary">Summary</h2>
<p>The <code>background-repeat</code> <a href="/en-US/docs/CSS" title="CSS">CSS</a> property defines how background images are repeated. A background image can be repeated along the horizontal axis, the vertical axis, both, or not repeated at all. When the repetition of the image tiles doesn't let them exactly cover the background, the way adjustments are done can be controlled by the author: by default, the last image is clipped, but the different tiles can instead be re-sized, or space can be inserted between the tiles.</p>
<div class="note">
  <strong>Note:</strong> 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-repeat</code> CSS property, the value of this property is then reset to its initial value by the shorthand property.</div>
<ul class="cssprop">
  <li><dfn>{{Xref_cssinitial()}}</dfn> <code>repeat</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>
<h2 id="Syntax">Syntax</h2>
<pre class="eval syntaxbox">
background-repeat: <em>repeat-style</em>[, <em>repeat-style</em>]*
</pre>
<p>where:</p>
<dl>
  <dt>
    <em>repeat-style</em></dt>
  <dd>
    Is following either the one-value syntax — and in that case the values are shorthand for ther two-value equivalent:<br />
    <table class="standard-table">
      <tbody>
        <tr>
          <td><code>repeat-x</code></td>
          <td>is the equivalent of <code>repeat no-repeat</code></td>
        </tr>
        <tr>
          <td><code>repeat-y</code></td>
          <td>is the equivalent of <code>no-repeat repeat</code></td>
        </tr>
        <tr>
          <td><code>repeat</code></td>
          <td>is the equivalent of <code>repeat repeat</code></td>
        </tr>
        <tr>
          <td><code>space</code></td>
          <td>is the equivalent of <code>space space</code></td>
        </tr>
        <tr>
          <td><code>round</code></td>
          <td>is the equivalent of <code>round round</code></td>
        </tr>
        <tr>
          <td><code>no-repeat</code></td>
          <td>is the equivalent of <code>no-repeat no-repeat</code></td>
        </tr>
      </tbody>
    </table>
    Or the two-value syntax where the first value represents the horizontal behavior of the repetition and the second value the vertical behavior:<br />
    <br />
    <table class="standard-table">
      <tbody>
        <tr>
          <td><code>repeat</code></td>
          <td>The image is repeated in the given direction as much as needed to cover the whole background image painting area. The last image may be clipped if the whole thing won't fit in the remaining area.</td>
        </tr>
        <tr>
          <td><code>space</code></td>
          <td>The image is repeated in the given direction as much as needed to cover most of the background image painting area, without clipping an image. The remaining non-covered space is spaced out evenly between the images. The first and last images touches the edge of the element. The value of the {{ cssxref("background-position") }} CSS property is ignored for the concerned direction, except if one single image is greater than the background image painting area, which is the only case where an image can be clipped when the <code>space</code> value is used.</td>
        </tr>
        <tr>
          <td><code>round</code></td>
          <td>The image is repeated in the given direction as much as needed to cover most of the background image painting area, without clipping an image. If it doesn't cover exactly the area, the tiles are resized in that direction in order to match it.</td>
        </tr>
        <tr>
          <td><code>no-repeat</code></td>
          <td>The image is not repeated (and hence the background image painting area will not necessarily been entirely covered). The position of the non-repeated background image is defined by the {{ cssxref("background-position") }} CSS property.</td>
        </tr>
      </tbody>
    </table>
  </dd>
</dl>
<h2 id="Examples">Examples</h2>
<p>{{ CSSLiveSample("background-repeat") }}</p>
<pre class="brush:css; highlight:[3,8,13];">
.exampleone {
  background-image: url("logo.png");
  background-repeat: repeat-x;
}

.exampletwo {
  background-image: url("logo.png");
  background-repeat: no-repeat;
}

.examplethree {
  background-image: url("img1.png"), url("img2.png");
  background-repeat: repeat-x, repeat-y;
} 
</pre>
<p>Each image is matched with the corresponding repeat style, from first specified to last.</p>
<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-repeat', 'background-repeat') }}</td>
      <td>{{ Spec2('CSS3 Backgrounds') }}</td>
      <td>Added support for multiple backgrounds images, the two-value syntax allowing distinct repetition behavior for the horizontal and vertical directions, the <code>space</code> and <code>round</code> keywords, and for backgrounds on inline-level element by defining precisely the background painting area.</td>
    </tr>
    <tr>
      <td>{{ SpecName('CSS2.1', 'colors.html#propdef-background-repeat', 'background-repeat') }}</td>
      <td>{{ Spec2('CSS2.1') }}</td>
      <td>No significant changes</td>
    </tr>
    <tr>
      <td>{{ SpecName('CSS1', '#background-repeat', 'background-repeat') }}</td>
      <td>{{ Spec2('CSS1') }}</td>
      <td>&nbsp;</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>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 (85)</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 (312)</td>
      </tr>
      <tr>
        <td>Different values for X &amp; Y directions (two-value syntax)</td>
        <td>{{ CompatVersionUnknown() }}</td>
        <td>{{ CompatGeckoDesktop("13.0") }} {{ bug("548375") }}</td>
        <td>9.0</td>
        <td>{{ CompatVersionUnknown() }}</td>
        <td>{{ CompatVersionUnknown() }}</td>
      </tr>
      <tr>
        <td><code>round</code> and <code>space</code> keywords</td>
        <td>{{ CompatNo() }}</td>
        <td>{{ CompatNo() }} {{ bug("548372") }}</td>
        <td>9.0</td>
        <td>10.5</td>
        <td>{{ CompatNo() }}</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>Multiple backgrounds</td>
        <td>{{ CompatUnknown() }}</td>
        <td>{{ CompatUnknown() }}</td>
        <td>{{ CompatUnknown() }}</td>
        <td>{{ CompatUnknown() }}</td>
        <td>{{ CompatUnknown() }}</td>
      </tr>
      <tr>
        <td>Different values for X &amp; Y directions (two-value syntax)</td>
        <td>{{ CompatUnknown() }}</td>
        <td>{{ CompatUnknown() }}</td>
        <td>{{ CompatUnknown() }}</td>
        <td>{{ CompatUnknown() }}</td>
        <td>{{ CompatUnknown() }}</td>
      </tr>
      <tr>
        <td><code>round</code> and <code>space</code> keywords</td>
        <td>{{ CompatUnknown() }}</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>Background-related CSS Properties: {{ CSS_Reference:Background() }}</li>
  <li><a href="/en-US/docs/CSS/Multiple_backgrounds" title="en-US/docs/CSS/Multiple backgrounds">Multiple backgrounds</a></li>
</ul>
Revert to this revision