background-repeat
Quick Summary for background-repeat
The background-repeat CSS property sets how background images are repeated. A background image can be repeated along the horizontal and vertical axes, or not repeated at all.
Code Usage for background-repeat
/* Keyword values */ background-repeat: repeat-x; background-repeat: repeat-y; background-repeat: repeat; background-repeat: space; background-repeat: round; background-repeat: no-repeat;  /* Two-value syntax: horizontal | vertical */ background-repeat: repeat space; background-repeat: repeat repeat; background-repeat: round space; background-repeat: no-repeat round;  /* Global values */ background-repeat: inherit; background-repeat: initial; background-repeat: revert; background-repeat: unset; 
More Details for background-repeat

background-repeat

The background-repeat CSS property sets how background images are repeated. A background image can be repeated along the horizontal and vertical axes, or not repeated at all.

By default, the repeated images are clipped to the size of the element, but they can be scaled to fit (using round) or evenly distributed from end to end (using space).

Syntax

/* Keyword values */ background-repeat: repeat-x; background-repeat: repeat-y; background-repeat: repeat; background-repeat: space; background-repeat: round; background-repeat: no-repeat;  /* Two-value syntax: horizontal | vertical */ background-repeat: repeat space; background-repeat: repeat repeat; background-repeat: round space; background-repeat: no-repeat round;  /* Global values */ background-repeat: inherit; background-repeat: initial; background-repeat: revert; background-repeat: unset; 

Values

<repeat-style>

The one-value syntax is a shorthand for the full two-value syntax:

Single value Two-value equivalent
repeat-x repeat no-repeat
repeat-y no-repeat repeat
repeat repeat repeat
space space space
round round round
no-repeat no-repeat no-repeat

In the two-value syntax, the first value represents the horizontal repetition behavior and the second value represents the vertical behavior. Here is an explanation of how each option works for either direction:

repeat The image is repeated as much as needed to cover the whole background image painting area. The last image will be clipped if it doesn't fit.
space The image is repeated as much as possible without clipping. The first and last images are pinned to either side of the element, and whitespace is distributed evenly between the images. The background-position property is ignored unless only one image can be displayed without clipping. The only case where clipping happens using space is when there isn't enough room to display one image.
round As the allowed space increases in size, the repeated images will stretch (leaving no gaps) until there is room (space left >= half of the image width) for another one to be added. When the next image is added, all of the current ones compress to allow room. Example: An image with an original width of 260px, repeated three times, might stretch until each repetition is 300px wide, and then another image will be added. They will then compress to 225px.
no-repeat The image is not repeated (and hence the background image painting area will not necessarily be entirely covered). The position of the non-repeated background image is defined by the background-position CSS property.

Formal definition

Initial valuerepeat
Applies toall elements. It also applies to ::first-letter and ::first-line.
Inheritedno
Computed valuea list, each item consisting of two keywords, one per dimension
Animation typediscrete

Formal syntax

<repeat-style>#

where <repeat-style> = repeat-x | repeat-y | [ repeat | space | round | no-repeat ]{1,2}

Examples

Setting background-repeat

HTML
<ol>   <li>no-repeat     <div class="one"></div>   </li>   <li>repeat     <div class="two"></div>   </li>   <li>repeat-x     <div class="three"></div>   </li>   <li>repeat-y     <div class="four"></div>   </li>   <li>space     <div class="five"></div>   </li>   <li>round     <div class="six"></div>   </li>   <li>repeat-x, repeat-y (multiple images)     <div class="seven"></div>   </li> </ol> 
CSS
/* Shared for all DIVS in example */ ol, li {   margin: 0;   padding: 0; } li {   margin-bottom: 12px; } div {     background-image: url(starsolid.gif);     width: 160px;     height: 70px; }  /* Background repeats */ .one {   background-repeat: no-repeat; } .two {   background-repeat: repeat; } .three {   background-repeat: repeat-x; } .four {   background-repeat: repeat-y; } .five {   background-repeat: space; } .six {   background-repeat: round; }  /* Multiple images */ .seven {   background-image:  url(starsolid.gif),                      url(https://developer.mozilla.org/static/img/favicon32.png);   background-repeat: repeat-x,                      repeat-y;   height: 144px; } 
Result

In this example, each list item is matched with a different value of background-repeat.

Specifications

Specification
CSS Backgrounds and Borders Module Level 4 # the-background-repeat

See also

Using multiple backgrounds Select your preferred language English (US)DeutschEspañolFrançais日本語한국어Русский中文 (简体) Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote


seren spirit :(
Random CSS Property

<angle>

The <angle> CSS data type represents an angle value expressed in degrees, gradians, radians, or turns. It is used, for example, in <gradient>s and in some transform functions.
angle#rad css reference