background-repeat

Geoff Graham on Updated on
##description##
Ad
`, } ); } })();

If a background-image property is specified, the background-repeat property in CSS defines if (and how) it will repeat.

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

Values

The background-repeat property accepts the following values:

/* Single value syntax */
background-repeat: repeat; /* Default value */
background-repeat: repeat-x;
background-repeat: repeat-y
background-repeat: no-repeat;
background-repeat: round;
background-repeat: space;

/* Two value syntax: <horizontal> | <vertical> */
background-repeat: repeat no-repeat;
background-repeat: round space;
background-repeat: repeat round;
background-repeat: no-repeat space;
background-repeat: round no-repeat;

/* Global values */
background-repeat: inherit;
background-repeat: initial;
background-repeat: revert;
background-repeat: revert-layer;
background-repeat: unset;

Syntax

background-repeat: repeat-x | repeat-y | [repeat | space | round | no-repeat]{1,2};

The background-repeat property accepts one or two values. A single value sets the background image’s repeating pattern in both the horizontal and vertical directions. Two values individually set the repeating pattern in each direction, respectively.

Single valueThe same as…
repeat-xrepeat no-repeat
repeat-yno-repeat repeat
repeatrepeat repeat
spacespace space
roundround round
no-repeatno-repeat no-repeat

The background shorthand property

The background-repeat property is a constituent of the background shorthand property. It follows the background-size in the order of operations:

body {
  background:
     url(sweettexture.jpg)     /* background-image */
     top center / 100px 100px  /* background-bposition / background-size */
     no-repeat                 /* background-repeat */
     fixed                     /* background-attachment */
     padding-box               /* background-origin */
     content-box               /* background-clip */
     red;                      /* background-color */
}

Multiple backgrounds

You can also comma-separate multiple values if you’re dealing with multiple backgrounds. Let’s say we have an element with two background images:

.some-element {
  background-image: url("star-outline.svg"), url("star-filled.svg");
}

We can set the background-repeat behavior for each one on the same declaration as long as we separate them with commas:

.some-element {
  background-image: url("star-outline.svg"), url("star-filled.svg");
  background-repeat: no-repeat, repeat-x;
}

Without the comma, CSS will simply think you’re using the single-value syntax and setting the vertical and horizontal directions for both background images.

And, yes, we can indeed comma-separate the two-value syntax as well:

.some-element {
  background-image: url("star-outline.svg"), url("star-filled.svg");
  background-repeat: no-repeat repeat-x, no-repeat repeat-y;
}

In other words, there are many, many possibilities for configuring how background images repeat with as many background images as we want.

Demo

Compare the repeating patterns for each property value — and combinations of them — using the controls in the following demo.

The differences between repeat, round, and space are clearer to see when you’re able to resize the element that contains the background image. Update the size of each example in the following demo to compare the different behaviors.

The round value is super helpful in those pretty rare times that you need to display the full background image for each repetition without cropping or altering it. The following demo uses a background image to form a border around an element using background-repreat: round to prevent the border from clipping the image as it would with default repeat behavior.

Try adjusting the size of the box to see how round forces the full image to display, no matter what size the box is.

Or, hey, maybe you’ve got hamburger on the brain and decide to use a round repeat to create a stack of full-size patties. Resize the following demo vertically to make a larger burger.

Here’s another fun demo with hamburgers demonstrating background-repeat: round;.

Browser support

The background-repeat property is supported everywhere and always has been, except Android’s built-in browser, which lacked support between versions 2.1 to 4.3.