CSS background-repeat Property
The background-repeat property controls whether and how background images repeat horizontally and vertically within an element.
By default, background images repeat in both directions to fill the background painting area. The property can disable repetition, repeat along one axis, distribute complete tiles with spacing, or resize tiles to fit without clipping. It applies to image backgrounds, including CSS gradients.
background-repeat Syntax
selector {
background-repeat: repeat;
}
The property accepts one repeat keyword, two keywords for separate horizontal and vertical behavior, or a comma-separated list for multiple background images.
.repeat-both {
background-repeat: repeat;
}
.no-repetition {
background-repeat: no-repeat;
}
.repeat-horizontal {
background-repeat: repeat-x;
}
.repeat-vertical {
background-repeat: repeat-y;
}
.spaced-tiles {
background-repeat: space;
}
.resized-tiles {
background-repeat: round;
}
.mixed-repetition {
background-repeat: repeat no-repeat;
}
.multiple-backgrounds {
background-repeat: no-repeat, repeat;
}
The property also accepts CSS-wide values such as inherit, initial, revert, revert-layer, and unset.
Property Values
| Value | Description |
|---|---|
repeat |
Repeats the background image in both directions. Tiles may be clipped at the painting area's edges. |
no-repeat |
Displays one copy of the background image without repetition. |
repeat-x |
Repeats the image horizontally but not vertically. |
repeat-y |
Repeats the image vertically but not horizontally. |
space |
Repeats complete image tiles with equal spacing between them when at least two tiles fit. |
round |
Resizes repeated image tiles so an integer number fits within the background positioning area. |
<repeat-style> <repeat-style> |
Controls horizontal and vertical repetition independently using two values. |
comma-separated list |
Assigns different repetition settings to multiple background image layers. |
The property applies to all elements, is not inherited, and has an initial value of repeat. Its computed value is a list of horizontal and vertical repetition styles. The property is not animatable.
When two values are specified, the first controls horizontal repetition and the second controls vertical repetition.
How background-repeat Works
When an element has a background image, the browser determines its rendered size and position before applying the repetition rules.
.patterned-panel {
width: 300px;
height: 180px;
background-image: url("pattern.png");
background-repeat: repeat;
}
The browser repeats the image horizontally and vertically to cover the background painting area.
Background Tiles
Each repeated copy of the background image is called a tile. The tile's dimensions are determined by the rendered image size, which can be changed with background-size.
For example, a background image rendered at 40 by 40 pixels creates a grid of 40-pixel tiles when background-repeat: repeat is used.
Positioning and Painting Areas
The background-origin property determines the positioning area used to establish the image's location. The background-clip property determines where the background is painted.
These areas can differ. Repeated tiles may extend beyond the positioning area but are clipped at the background painting boundary.
Background Images Do Not Affect Layout
Repeating a background image does not increase the dimensions of an element or create additional HTML content.
The background is decorative and remains behind the element's foreground content.
repeat and no-repeat
The repeat and no-repeat values provide the most common background repetition behaviors.
The repeat Value
.repeating-pattern {
background-image: url("pattern.png");
background-repeat: repeat;
}
The image repeats in both directions. When the available area is not an exact multiple of the tile dimensions, partial tiles may appear along the edges.
This is useful for seamless textures, repeating decorative patterns, and small images designed to cover large areas.
The no-repeat Value
.single-image {
background-image: url("logo.png");
background-repeat: no-repeat;
}
Only one copy of the image is displayed. By default, it is positioned at the top-left corner of the background positioning area.
Centering a Single Image
.centered-image {
background-image: url("logo.png");
background-repeat: no-repeat;
background-position: center;
}
The image is centered without being repeated.
Covering an Element with One Image
.hero-background {
background-image: url("hero.jpg");
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
This combination is commonly used for banners, hero sections, and image-backed cards.
Horizontal and Vertical Repetition
The repeat-x and repeat-y values repeat a background image along only one axis.
The repeat-x Value
.horizontal-pattern {
background-image: url("pattern.png");
background-repeat: repeat-x;
}
The image repeats from left to right but does not repeat vertically. The row of tiles is positioned using background-position.
The repeat-y Value
.vertical-pattern {
background-image: url("pattern.png");
background-repeat: repeat-y;
}
The image repeats from top to bottom but does not repeat horizontally. The column of tiles is positioned using background-position.
Equivalent Two-Value Syntax
| Single Value | Equivalent Two-Value Syntax |
|---|---|
repeat-x |
repeat no-repeat |
repeat-y |
no-repeat repeat |
repeat |
repeat repeat |
no-repeat |
no-repeat no-repeat |
Practical Examples
.top-decoration {
background-image: url("horizontal-pattern.png");
background-repeat: repeat-x;
background-position: left top;
}
.side-decoration {
background-image: url("vertical-pattern.png");
background-repeat: repeat-y;
background-position: left top;
}
Single-axis repetition is useful for decorative strips, repeated borders, and other designs that require tiling in one direction only.
The space Value
The space value repeats complete image tiles without clipping them, distributing any remaining space evenly between the tiles.
.spaced-pattern {
background-image: url("pattern.png");
background-size: 40px 40px;
background-repeat: space;
}
When at least two tiles fit along an axis, the first and last tiles align with the positioning area's edges, and the remaining space is distributed between them.
How Spacing Is Calculated
Suppose the background positioning area is 250 pixels wide and each tile is 40 pixels wide.
Six tiles fit within the width, occupying 240 pixels. The remaining 10 pixels are distributed across the five gaps between the tiles, creating 2-pixel gaps.
When Only One Tile Fits
If only one complete tile fits along an axis, the image is not repeated along that axis. Its placement is determined by background-position.
Spacing on One Axis
.horizontal-spacing {
background-repeat: space no-repeat;
}
.vertical-spacing {
background-repeat: no-repeat space;
}
The first example distributes tiles horizontally and displays only one row. The second distributes tiles vertically and displays only one column.
Spacing Without Scaling
The space value does not resize the tiles. It adjusts only the spacing between them.
This makes it useful for repeating icons or decorative elements that must retain their original dimensions.
The round Value
The round value resizes repeated background tiles so a whole number fits within the background positioning area without clipping.
.rounded-pattern {
background-image: url("pattern.png");
background-size: 45px 45px;
background-repeat: round;
}
The browser adjusts the tile dimensions so the repeated images fit the available area evenly.
How Tile Resizing Works
For example, if the positioning area is 250 pixels wide and the specified tile width is 45 pixels, the browser chooses an integer number of tiles that fits the width most closely.
Six tiles are selected, and each is resized to approximately 41.67 pixels wide so they fill the 250-pixel area.
Resizing on One Axis
.horizontal-rounding {
background-repeat: round no-repeat;
}
.vertical-rounding {
background-repeat: no-repeat round;
}
The first declaration resizes tiles horizontally while displaying one row. The second resizes tiles vertically while displaying one column.
Preserving Aspect Ratio
When round is used on one axis and the other background dimension is auto, the browser may adjust the automatic dimension to preserve the image's intrinsic aspect ratio.
When both axes use round, each dimension is adjusted independently, so the image may be stretched.
Choosing Between space and round
| Value | Tile Size | Spacing |
|---|---|---|
space |
Preserves tile dimensions. | Distributes remaining space between tiles. |
round |
Adjusts tile dimensions. | Fits tiles together without additional gaps. |
Use space when image dimensions must remain unchanged. Use round when seamless tiling without clipped edge tiles is more important.
Two-Value Syntax
Two-value syntax allows the horizontal and vertical repetition styles to be controlled independently.
selector {
background-repeat: horizontal vertical;
}
The first value determines horizontal repetition. The second determines vertical repetition.
Combining Different Styles
.horizontal-only {
background-repeat: repeat no-repeat;
}
.vertical-only {
background-repeat: no-repeat repeat;
}
.horizontal-space {
background-repeat: space no-repeat;
}
.vertical-round {
background-repeat: no-repeat round;
}
.mixed-tiling {
background-repeat: round space;
}
The last example adjusts tile widths to fit horizontally and distributes complete tiles with spacing vertically.
Using the Same Value on Both Axes
.repeat-both {
background-repeat: repeat repeat;
}
.space-both {
background-repeat: space space;
}
.round-both {
background-repeat: round round;
}
When both axes use the same repetition style, the second value can be omitted.
Invalid Combinations
The legacy keywords repeat-x and repeat-y are single-value forms. They cannot be combined with another repetition keyword in the same layer.
/* Valid */
.example-one {
background-repeat: repeat-x;
}
.example-two {
background-repeat: repeat no-repeat;
}
/* Invalid */
.example-three {
background-repeat: repeat-x no-repeat;
}
Use the two-value form when horizontal and vertical behavior must be specified separately.
Working with background-position
The background-position property determines where a background image is placed before its repetition pattern is applied.
Positioning a Non-Repeating Image
.centered-background {
background-image: url("logo.png");
background-repeat: no-repeat;
background-position: center;
}
The image is displayed once at the center of the positioning area.
Positioning a Repeated Row
.bottom-pattern {
background-image: url("pattern.png");
background-repeat: repeat-x;
background-position: left bottom;
}
The image repeats horizontally along the bottom of the positioning area.
Positioning a Repeated Column
.right-pattern {
background-image: url("pattern.png");
background-repeat: repeat-y;
background-position: right top;
}
The image repeats vertically along the right side of the positioning area.
Positioning with space and round
When multiple tiles fit using space, their placement along that axis is determined by the spacing rules rather than background-position.
With round, the tiles fill the positioning area along the repeated axis, so changing the position on that axis generally has no visible effect.
Positioning remains useful on an axis that uses no-repeat, or when only one tile fits using space.
Working with background-size
The background-size property controls the dimensions of background image tiles before repetition is applied.
Creating Smaller Tiles
.small-pattern {
background-image: url("pattern.png");
background-size: 30px 30px;
background-repeat: repeat;
}
The image is rendered at 30 by 30 pixels and repeated to fill the background painting area.
Creating Larger Tiles
.large-pattern {
background-image: url("pattern.png");
background-size: 80px 80px;
background-repeat: repeat;
}
Larger tiles produce fewer repetitions within the same area.
Using cover
.hero {
background-image: url("hero.jpg");
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
The image scales to cover the positioning area, and repetition is disabled to avoid unnecessary additional copies.
Using contain
.contained-background {
background-image: url("logo.png");
background-size: contain;
background-position: center;
background-repeat: no-repeat;
}
The image scales to fit within the positioning area while preserving its aspect ratio.
When background-size is combined with round, the browser may further adjust the specified tile dimensions to fit an integer number of repetitions.
Multiple Background Layers
The background-repeat property accepts comma-separated values for controlling repetition on multiple background image layers.
.layered-background {
background-image: url("logo.png"), url("pattern.png");
background-repeat: no-repeat, repeat;
background-position: center, left top;
}
The first image appears once in the center. The second image repeats behind it.
Different Repetition Styles
.three-layer-background {
background-image: url("icon.png"), url("stripe.png"), url("texture.png");
background-repeat: no-repeat, repeat-x, repeat;
background-position: center, left top, left top;
}
The first image is displayed once, the second repeats horizontally, and the third repeats in both directions.
Matching Values to Layers
Each repetition value corresponds to the background image at the same position in the comma-separated list.
If fewer repetition values are provided than image layers, the browser repeats the list as necessary. Extra values are not used when there are fewer image layers.
Background Layer Order
The first background image is painted above subsequent images. The background color, when present, is painted beneath all background image layers.
Different repetition styles can be combined to create layered textures, decorative borders, and centered graphics over repeating patterns.
Using the background Shorthand
The background-repeat property can be specified as part of the background shorthand.
.banner {
background: url("banner.jpg") center no-repeat;
}
The image is centered and displayed once.
Combining Position, Size, and Repetition
.hero {
background: #173b5e url("hero.jpg") center / cover no-repeat;
}
The slash separates the background position from the background size. The no-repeat value prevents the image from tiling.
Repeating a Pattern
.patterned-panel {
background: #f4f8fc url("pattern.png") left top / 40px 40px repeat;
}
The image is sized to 40 by 40 pixels and repeated in both directions over the background color.
Shorthand Reset Behavior
.panel {
background-repeat: no-repeat;
background: url("pattern.png");
}
The final shorthand declaration resets background-repeat to its initial value of repeat.
To preserve a repetition setting, specify it in the shorthand or place the longhand declaration afterward.
.panel {
background: url("pattern.png");
background-repeat: no-repeat;
}
background-repeat Example
The following example compares six repetition styles using the same small circular gradient image. Each panel uses identical background dimensions so the differences are easy to see.
<div class="background-repeat-demo">
<div class="repeat-box repeat">repeat</div>
<div class="repeat-box no-repeat">no-repeat</div>
<div class="repeat-box repeat-x">repeat-x</div>
<div class="repeat-box repeat-y">repeat-y</div>
<div class="repeat-box space">space</div>
<div class="repeat-box round">round</div>
</div>
.background-repeat-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
gap: 15px;
}
.repeat-box {
display: flex;
align-items: flex-end;
justify-content: center;
min-height: 170px;
padding: 10px;
box-sizing: border-box;
border: 2px solid #1769aa;
border-radius: 6px;
background-color: #e8f2fb;
background-image: radial-gradient(circle, #1769aa 0 60%, #69b7e8 62% 75%, transparent 77%);
background-size: 42px 42px;
background-position: left top;
color: #173b5e;
font-weight: bold;
text-align: center;
}
.repeat-box.repeat {
background-repeat: repeat;
}
.repeat-box.no-repeat {
background-repeat: no-repeat;
}
.repeat-box.repeat-x {
background-repeat: repeat-x;
}
.repeat-box.repeat-y {
background-repeat: repeat-y;
}
.repeat-box.space {
background-repeat: space;
}
.repeat-box.round {
background-repeat: round;
}
Each panel uses the same circular gradient. Only the background-repeat value changes.
The repeat panel tiles the image in both directions, while no-repeat displays a single image.
The repeat-x and repeat-y panels repeat along only one axis. The space panel distributes complete tiles with gaps, and the round panel adjusts tile dimensions so they fit the available area.
Because the demo uses a CSS gradient instead of an external image, the example works without downloading additional image files.
Important Considerations
Keep the following points in mind when using background-repeat:
- Default value: The initial value is
repeat, which tiles the image horizontally and vertically. - Single images: Use
no-repeatfor logos, photographs, and decorative graphics that should appear only once. - Horizontal repetition: Use
repeat-xorrepeat no-repeatto repeat along the horizontal axis. - Vertical repetition: Use
repeat-yorno-repeat repeatto repeat along the vertical axis. - Tile spacing: The
spacevalue distributes complete tiles without changing their dimensions. - Tile resizing: The
roundvalue adjusts tile dimensions to fit a whole number of repetitions. - Two-value syntax: The first value controls horizontal repetition, and the second controls vertical repetition.
- Background size: The rendered image dimensions determine the size and number of repeated tiles.
- Background position: Positioning determines where the repetition pattern begins or where a non-repeating image appears.
- Clipping: Repeated tiles may be clipped at the edges of the background painting area.
- Multiple layers: Comma-separated values allow different repetition settings for individual background images.
- Gradients: CSS gradients are background images and can be repeated just like image files.
- Shorthand resets: A later
backgroundshorthand declaration resets repetition torepeatunless another value is specified. - Layout: Repeating background images does not change the element's dimensions or create additional content.
- Accessibility: Avoid highly detailed repeating backgrounds behind text when they reduce readability or contrast.
Choose the repetition style based on whether the image should appear once, tile continuously, maintain spacing, or resize to fit the available area.
Browser Support
The background-repeat property has Baseline Widely available status and is supported in modern versions of Chrome, Edge, Firefox, Safari, and other major browsers.
The repeat, no-repeat, repeat-x, and repeat-y values have long-standing browser support. The space and round values are also supported by modern browsers but may not work in older browser versions.
Providing a Fallback
.decorative-pattern {
background-image: url("pattern.png");
background-repeat: repeat;
background-repeat: space;
}
Browsers that do not recognize space can retain the earlier repeat declaration.
Visit Can I Use? to check compatibility for advanced background repetition values.
Specifications
The background-repeat property is defined in the CSS Backgrounds and Borders Module Level 3 specification.
