CSS background-repeat-x Property
The background-repeat-x property controls how an element's background images repeat along the horizontal axis.
It can repeat image tiles continuously, display a single tile, distribute complete tiles with spacing, or resize tiles to fit the available width. Unlike the repeat-x value of background-repeat, this longhand property changes only horizontal repetition and leaves vertical repetition controlled by background-repeat-y.
background-repeat-x Syntax
selector {
background-repeat-x: repeat;
}
The property accepts one horizontal repetition keyword or a comma-separated list for multiple background image layers.
.repeat-horizontal {
background-repeat-x: repeat;
}
.single-horizontal-tile {
background-repeat-x: no-repeat;
}
.spaced-horizontal-tiles {
background-repeat-x: space;
}
.resized-horizontal-tiles {
background-repeat-x: round;
}
.multiple-horizontal-styles {
background-repeat-x: no-repeat, repeat;
}
The property also accepts CSS-wide values such as inherit, initial, revert, revert-layer, and unset.
Each value controls only horizontal repetition. The vertical repetition style is determined separately.
Property Values
| Value | Description |
|---|---|
repeat |
Repeats background image tiles horizontally. Partial tiles may appear at the painting area's edges. |
no-repeat |
Displays one tile horizontally without creating additional copies along that axis. |
space |
Distributes complete tiles horizontally with equal spacing when at least two tiles fit. |
round |
Adjusts tile widths so an integer number of tiles fits across the background positioning area. |
comma-separated list |
Assigns different horizontal repetition styles to individual 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 repetition keywords, and its animation type is discrete.
The keywords repeat-x and repeat-y are values of the background-repeat shorthand, not valid values of background-repeat-x.
How background-repeat-x Works
The browser first determines the size and position of each background image. The background-repeat-x property then determines how copies of that image are arranged horizontally.
.patterned-panel {
width: 300px;
height: 160px;
background-image: url("pattern.png");
background-size: 40px 40px;
background-repeat-x: repeat;
background-repeat-y: no-repeat;
}
The background image is rendered at 40 by 40 pixels and repeated horizontally. Because vertical repetition is disabled, only one row of tiles is displayed.
Horizontal and Vertical Repetition Are Independent
Setting background-repeat-x does not automatically disable vertical repetition. If background-repeat-y remains at its initial value of repeat, the image can still repeat vertically.
.repeat-both-directions {
background-repeat-x: repeat;
background-repeat-y: repeat;
}
This produces repetition in both directions, equivalent to background-repeat: repeat.
Background Positioning and Painting
The background-origin property establishes the background positioning area. The background-clip property determines where the repeated background is painted.
Tiles can extend beyond the positioning area and may be clipped at the background painting boundary.
Background Repetition Does Not Change Layout
Repeating an image horizontally does not increase the element's width, change its padding, or move its foreground content.
The repeat Value
The repeat value repeats background image tiles continuously along the horizontal axis.
.horizontal-pattern {
background-image: url("pattern.png");
background-size: 40px 40px;
background-repeat-x: repeat;
background-repeat-y: no-repeat;
}
The image repeats from left to right, creating a horizontal row of tiles.
Partial Tiles
When the available width is not an exact multiple of the tile width, partial tiles may be visible at the edges of the background painting area.
For example, a 250-pixel-wide area using 40-pixel tiles can display six complete tiles and part of another tile, depending on the background position.
Repeating a Decorative Strip
.top-border-pattern {
min-height: 120px;
background-image: url("stripe.png");
background-size: 40px 12px;
background-repeat-x: repeat;
background-repeat-y: no-repeat;
background-position: left top;
}
This creates a repeating decorative strip along the top of the element.
Use repeat when continuous horizontal tiling is needed and clipped edge tiles are acceptable.
The no-repeat Value
The no-repeat value prevents a background image from repeating horizontally.
.single-column {
background-image: url("pattern.png");
background-repeat-x: no-repeat;
background-repeat-y: repeat;
}
The image appears in one vertical column because horizontal repetition is disabled while vertical repetition remains enabled.
Displaying One Background Image
.single-image {
background-image: url("logo.png");
background-repeat-x: no-repeat;
background-repeat-y: no-repeat;
background-position: center;
}
With repetition disabled on both axes, the image appears once at the center of the positioning area.
Positioning a Single Column
.right-column {
background-image: url("pattern.png");
background-size: 30px 30px;
background-repeat-x: no-repeat;
background-repeat-y: repeat;
background-position-x: right;
}
The image repeats vertically along the right side of the element without creating additional horizontal columns.
Use no-repeat when horizontal duplication is unnecessary or when only vertical repetition is desired.
The space Value
The space value repeats complete background tiles horizontally and distributes the remaining width evenly between them.
.spaced-pattern {
background-image: url("pattern.png");
background-size: 40px 40px;
background-repeat-x: space;
background-repeat-y: no-repeat;
}
When at least two tiles fit, the first and last tiles align with the edges of the positioning area, and equal gaps appear between the tiles.
Calculating Horizontal Spacing
Suppose the background positioning area is 250 pixels wide and each tile is 40 pixels wide.
Six complete tiles occupy 240 pixels. The remaining 10 pixels are distributed across five gaps, creating 2-pixel spaces between adjacent tiles.
When Only One Tile Fits
If only one complete tile fits horizontally, the image is displayed once along that axis. Its horizontal position is determined by background-position-x.
Maintaining Original Tile Width
The space value does not resize tiles. It adjusts only the spacing between them.
This makes it useful for decorative icons and repeating graphics that should maintain consistent dimensions across different container widths.
Spacing with Vertical Repetition
.spaced-columns {
background-image: url("pattern.png");
background-size: 40px 40px;
background-repeat-x: space;
background-repeat-y: repeat;
}
Complete tiles are spaced horizontally while the image repeats continuously in the vertical direction.
The round Value
The round value adjusts the widths of repeated background tiles so an integer number fits across the background positioning area.
.rounded-pattern {
background-image: url("pattern.png");
background-size: 45px 45px;
background-repeat-x: round;
background-repeat-y: no-repeat;
}
The browser determines how many tiles fit most closely and resizes their widths to fill the available horizontal space without gaps or clipped edge tiles.
How Tile Resizing Works
Consider a 250-pixel-wide positioning area with tiles initially specified as 45 pixels wide.
The browser selects six tiles and adjusts each tile to approximately 41.67 pixels wide, allowing them to fill the 250-pixel width.
Image Aspect Ratio
If the background height is specified as auto and the vertical repetition style is not round, the browser can adjust the automatic height to preserve the image's intrinsic aspect ratio.
.proportional-pattern {
background-image: url("pattern.png");
background-size: 45px auto;
background-repeat-x: round;
background-repeat-y: no-repeat;
}
When both axes use round, each dimension can be adjusted independently, potentially changing the image's proportions.
Comparing space and round
| Value | Horizontal Tile Size | Remaining Space |
|---|---|---|
space |
Preserved | Distributed between tiles |
round |
Adjusted to fit | No extra gaps between tiles |
Use round when filling the available width with complete tiles is more important than preserving the exact original tile width.
Working with background-repeat-y
The background-repeat-x and background-repeat-y properties control repetition along the horizontal and vertical axes independently.
Repeating Only Horizontally
.horizontal-only {
background-repeat-x: repeat;
background-repeat-y: no-repeat;
}
This produces a horizontal row of repeated images.
Repeating Only Vertically
.vertical-only {
background-repeat-x: no-repeat;
background-repeat-y: repeat;
}
This produces a vertical column of repeated images.
Using Different Styles on Each Axis
.mixed-repetition {
background-repeat-x: space;
background-repeat-y: round;
}
Tiles are distributed with equal horizontal spacing while their heights are adjusted to fit vertically.
Equivalent Shorthand Values
| Horizontal | Vertical | background-repeat Equivalent |
|---|---|---|
repeat |
no-repeat |
repeat-x |
no-repeat |
repeat |
repeat-y |
repeat |
repeat |
repeat |
no-repeat |
no-repeat |
no-repeat |
space |
round |
space round |
The longhand properties are useful when a design needs to change repetition along one axis while preserving the other axis's behavior.
Working with background-position
The background-position property determines the initial placement of the background image before the repetition pattern is applied.
Positioning a Horizontal Row
.bottom-strip {
background-image: url("stripe.png");
background-repeat-x: repeat;
background-repeat-y: no-repeat;
background-position: left bottom;
}
The image repeats horizontally along the bottom of the positioning area.
Positioning a Vertical Column
.right-strip {
background-image: url("stripe.png");
background-repeat-x: no-repeat;
background-repeat-y: repeat;
background-position: right top;
}
The image repeats vertically along the right edge.
Positioning a Non-Repeating Image
.centered-decoration {
background-image: url("decoration.png");
background-repeat-x: no-repeat;
background-repeat-y: no-repeat;
background-position: center;
}
The image is centered and displayed once.
Positioning with space and round
When multiple tiles fit horizontally using space, the spacing rules determine their horizontal placement rather than background-position-x.
With round, the resized tiles fill the horizontal positioning area, so changing their horizontal position generally has no visible effect.
Horizontal positioning remains useful when repetition is disabled or only one tile fits with space.
Working with background-size
The background-size property determines the dimensions of each background image tile before repetition is applied.
Using Small Tiles
.small-tiles {
background-image: url("pattern.png");
background-size: 25px 25px;
background-repeat-x: repeat;
background-repeat-y: no-repeat;
}
Smaller tiles produce more horizontal repetitions within the same width.
Using Large Tiles
.large-tiles {
background-image: url("pattern.png");
background-size: 80px 80px;
background-repeat-x: repeat;
background-repeat-y: no-repeat;
}
Larger tiles produce fewer horizontal repetitions.
Combining Size and Spacing
.spaced-icons {
background-image: url("icon.png");
background-size: 40px 40px;
background-repeat-x: space;
background-repeat-y: no-repeat;
}
The tiles retain their specified width while the browser distributes the remaining horizontal space between them.
Combining Size and Rounding
.fitted-pattern {
background-image: url("pattern.png");
background-size: 45px 45px;
background-repeat-x: round;
background-repeat-y: no-repeat;
}
The browser may adjust the specified 45-pixel tile width to fit a complete number of tiles across the positioning area.
The background-size property is especially important when working with space and round, because tile dimensions determine how many repetitions fit.
Multiple Background Layers
The background-repeat-x property accepts comma-separated values to control horizontal repetition independently for multiple background image layers.
.layered-panel {
background-image: url("logo.png"), url("pattern.png");
background-repeat-x: no-repeat, repeat;
background-repeat-y: no-repeat, repeat;
background-position: center, left top;
}
The first image appears once at the center. The second image repeats in both directions behind it.
Different Horizontal Repetition Styles
.three-layers {
background-image: url("icon.png"), url("stripe.png"), url("texture.png");
background-repeat-x: no-repeat, space, round;
background-repeat-y: no-repeat, no-repeat, repeat;
background-position: center, left top, left top;
}
The first image is displayed once, the second is distributed horizontally with spacing, and the third is resized horizontally to fit complete tiles.
Matching Values to Layers
Each horizontal repetition value corresponds to the background image at the same position in the comma-separated list.
If fewer repetition values are specified than background 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 image layers. The background color is painted beneath all background images.
Combining different horizontal and vertical repetition styles can create layered textures, decorative strips, and repeating graphic arrangements.
Shorthand Properties and Resets
The background-repeat-x property is the horizontal longhand component of background-repeat.
.horizontal-strip {
background-repeat-x: repeat;
background-repeat-y: no-repeat;
}
This is equivalent to:
.horizontal-strip {
background-repeat: repeat-x;
}
Changing Only Horizontal Repetition
.panel {
background-repeat: no-repeat;
background-repeat-x: repeat;
}
The final declaration enables horizontal repetition while leaving vertical repetition disabled.
Shorthand Override Behavior
.panel {
background-repeat-x: space;
background-repeat: repeat;
}
The later background-repeat shorthand sets both axes to repeat, replacing the earlier horizontal space setting.
Using the background Shorthand
.panel {
background-repeat-x: no-repeat;
background: url("pattern.png");
}
The final background shorthand resets horizontal and vertical repetition to their initial value of repeat.
To preserve a horizontal repetition setting, place the longhand declaration after the shorthand.
.panel {
background: url("pattern.png") no-repeat;
background-repeat-x: repeat;
}
This produces horizontal repetition while keeping vertical repetition disabled.
A Compatibility-Friendly Alternative
.panel {
background-image: url("pattern.png");
background-repeat: space no-repeat;
}
The two-value background-repeat syntax expresses the same horizontal and vertical behavior without requiring the separate longhand properties.
background-repeat-x Example
The following example compares four horizontal repetition styles: repeat, no-repeat, space, and round.
Each panel uses the same circular gradient image with vertical repetition disabled, allowing the horizontal differences to be seen clearly.
<div class="background-repeat-x-demo">
<div class="repeat-box repeat">repeat</div>
<div class="repeat-box no-repeat">no-repeat</div>
<div class="repeat-box space">space</div>
<div class="repeat-box round">round</div>
</div>
.background-repeat-x-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
gap: 15px;
}
.background-repeat-x-demo .repeat-box {
display: flex;
align-items: flex-end;
justify-content: center;
min-height: 140px;
padding: 12px;
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: 48px 48px;
background-position: left top;
background-repeat-y: no-repeat;
color: #173b5e;
font-weight: bold;
text-align: center;
}
.background-repeat-x-demo .repeat {
background-repeat-x: repeat;
}
.background-repeat-x-demo .no-repeat {
background-repeat-x: no-repeat;
}
.background-repeat-x-demo .space {
background-repeat-x: space;
}
.background-repeat-x-demo .round {
background-repeat-x: round;
}
The browser result includes the equivalent background-repeat declarations as fallbacks so the example remains useful in browsers without separate horizontal repetition support.
The repeat panel displays a continuous row of tiles, while no-repeat displays one tile.
The space panel distributes complete tiles with equal gaps, and the round panel adjusts tile widths so they fit across the available area.
All four panels use no-repeat vertically, so the demonstration shows horizontal repetition without additional rows.
Important Considerations
Keep the following points in mind when using background-repeat-x:
- Default value: The initial value is
repeat. - Horizontal repetition: The property controls only repetition along the horizontal axis.
- Vertical repetition: Use
background-repeat-yto control repetition along the vertical axis. - Continuous tiling: The
repeatvalue allows tiles to repeat horizontally, including partial tiles at the edges. - Single horizontal tile: The
no-repeatvalue prevents additional horizontal copies but does not disable vertical repetition. - Tile spacing: The
spacevalue preserves tile widths and distributes remaining space between complete tiles. - Tile resizing: The
roundvalue adjusts tile widths to fit an integer number of repetitions. - Background size: The rendered image width affects how many horizontal tiles fit.
- Background position: Horizontal positioning affects non-repeating tiles and the alignment of repeated patterns.
- Background origin: The positioning area is determined by
background-originand defaults to the padding box. - Background clipping: Repeated tiles may be clipped at the background painting boundary.
- Multiple layers: Comma-separated values can assign different horizontal repetition styles to individual background images.
- Gradients: CSS gradients are background images and can be repeated horizontally.
- Shorthand resets: Later
background-repeatandbackgroundshorthand declarations can override the horizontal repetition setting. - Compatibility: Use the two-value
background-repeatshorthand as a fallback for browsers without support for the separate longhand. - Accessibility: Avoid repeating high-contrast or detailed graphics behind text when they interfere with readability.
Use background-repeat-x when a background image's horizontal repetition needs to change independently of its vertical repetition.
Browser Support
The background-repeat-x property has more limited compatibility than the established background-repeat shorthand. Support for the separate horizontal and vertical longhands varies by browser version.
For the broadest compatibility, use background-repeat with two values to specify horizontal and vertical repetition independently.
Providing a Fallback
.horizontal-pattern {
background-image: url("pattern.png");
background-repeat: space no-repeat;
background-repeat-x: space;
}
The first declaration establishes horizontal spacing with no vertical repetition. Browsers that support background-repeat-x can apply the second declaration without changing the vertical setting.
Using Feature Detection
.horizontal-pattern {
background-repeat: repeat-x;
}
@supports (background-repeat-x: space) {
.horizontal-pattern {
background-repeat-x: space;
}
}
The feature query applies horizontal spacing only when the browser recognizes the separate property and value.
Visit Can I Use? to check current browser compatibility before relying on this property in production.
Specifications
The background-repeat-x property is defined as a longhand component of background repetition in the CSS Backgrounds and Borders Module Level 4 specification. The related background-repeat shorthand is defined in Level 3.
