background-repeat

Decides whether and how the background image repeats to fill the element.

Initial value
repeat
Inherited
No
Animatable
no
Applies to
all elements
JavaScript
element.style.backgroundRepeat = "no-repeat"
On this page

Example

#
CSS
.notebook {
  background-image: linear-gradient(transparent 27px, rgba(167, 139, 250, 0.25) 28px);
  background-size: 100% 28px;
  background-repeat: repeat-y;
  line-height: 28px;
}
Preview

Definition and usage

#

By default, a background image smaller than the element repeats in both directions like tiles. The background-repeat property lets you turn this off (no-repeat) or limit repetition to one axis (repeat-x, repeat-y).

The space and round values repeat the image without cutting off the last tile: space adds gaps between the copies, and round slightly scales the image so a whole number of copies fits.

For background photos you almost always set no-repeat, and leave repetition for patterns and textures.

Syntax

#
Syntax
background-repeat: repeat | no-repeat | repeat-x | repeat-y | space | round;

Values

#
  • repeat

    Tiles in both directions, the last ones may be cut off.
  • no-repeat

    A single copy of the image.
  • repeat-x

    Repeats horizontally only.
  • space

    Whole tiles with equal gaps between them.
  • round

    Tiles slightly scaled so a whole number of them fits.

Values in practice

#

repeat

Tiles in both directions, the last ones may be cut off.
.demo { background-repeat: repeat; }

no-repeat

A single copy of the image.
.demo { background-repeat: no-repeat; }

repeat-x

Repeats horizontally only.
.demo { background-repeat: repeat-x; }

space

Whole tiles with equal gaps between them.
.demo { background-repeat: space; }

round

Tiles slightly scaled so a whole number of them fits.
.demo { background-repeat: round; }

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • Repeating gradients (repeating-linear-gradient) produce stripe patterns without any image files.
  • For photos set no-repeat, otherwise on large screens you will see copies of the image.

Related entries

#

Spotted a mistake or missing an example? Write to us.