bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/CSS/CSS Foundations
CSS•CSS Foundations

CSS Background Image Repeat

CSS background-repeat

Formula

The background - repeat property sets if/how a background image will be repeated.
By default, a background - image is repeated both vertically and horizontally.

Some images should be repeated only horizontally or vertically, or they will look strange, like this:

Example body

{
background-image: url("gradient_bg.png");
}

CSS background-repeat Horizontally

If the image above is repeated only horizontally (

background-repeat: repeat-x;

), the background will look better:

Example body

{
background-image: url("gradient_bg.png");
background-repeat: repeat-x;
}

Tip:

Formula

To repeat an image only vertically, use background - repeat: repeat - y;

CSS background-repeat: no-repeat

Formula

Showing the background image only once is also specified by the background - repeat property:

Example

Show the background image only once: body

{
background-image: url("img_tree.png");
background-repeat: no-repeat;
}

In the example above, the background image is placed in the same place as the text. We want to change the position of the image, so that it does not disturb the text too much.

CSS background-position

Formula

The background - position property is used to set the starting position of the background image.
By default, a background - image is placed at the top - left corner of an element.

Example

Formula

Position the background image in the top - right corner:

body

{
background-image: url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;
}

The CSS Background Repeat and Position Properties

Property

Description background-position

Formula

Sets the starting position of a background image background - repeat

Sets how a background image will be repeated

Video: CSS Background Repeat and Position

Previous

CSS Backgrounds

Next

CSS Background Shorthand