bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/CSS/CSS Foundations
CSS•CSS Foundations

CSS Background Image Repeat

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind CSS Background Image Repeat?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___-image: url("gradient_bg.png");
3Order

Put the learning moves in the order that makes the concept easiest to apply.

CSS background-repeat: no-repeat
CSS background-repeat Horizontally
CSS background-repeat

CSS background-repeat

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

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

Live preview

CSS background-repeat Horizontally

If the image above is repeated only horizontally ( background-repeat: repeat-x; ), the background will look better:

Example

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

Live preview

Tip

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

CSS background-repeat: no-repeat

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

Example

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

Live preview

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

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

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

Live preview

The CSS Background Repeat and Position Properties

PropertyDescription
background-positionSets the starting position of a background image
background-repeatSets how a background image will be repeated

Previous

CSS Background Image

Next

CSS Background Attachment