Master CSS From Scratch

Clear, interactive, and structured CSS lessons designed for beginners.

Background Repeat

The background-repeat property controls whether a background image should repeat inside an HTML element.

By default, a background image may repeat horizontally and vertically. CSS provides different values to control this behavior.

Background Repeat Flow

Background Image
→
background-repeat
→
Browser Output

Example 1: No Repeat

The no-repeat value displays the background image only once.

CSS Code
div {
    background-image: url("https://ciitinstitute.com/assets/mainlogo.png");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    background-color: #ffffff;
    min-height: 260px;
}
Output
Image appears only once

no-repeat prevents the image from repeating.

Example 2: Repeat

The repeat value repeats the background image horizontally and vertically.

CSS Code
div {
    background-image: url("https://images.unsplash.com/photo-1498050108023-c5249f4df085?auto=format&fit=crop&w=300&q=80");
    background-repeat: repeat;
    background-size: 180px 120px;
    min-height: 300px;
}
Output
Repeated Background

The image is repeated in both horizontal and vertical directions.

Example 3: Repeat-X

The repeat-x value repeats the image only horizontally.

CSS Code
div {
    background-image: url("https://images.unsplash.com/photo-1516321318423-f06f85e504b3?auto=format&fit=crop&w=300&q=80");
    background-repeat: repeat-x;
    background-size: 180px 120px;
    background-position: top left;
    min-height: 260px;
}
Output
Horizontal Repeat

The image repeats from left to right.

Example 4: Repeat-Y

The repeat-y value repeats the image only vertically.

CSS Code
div {
    background-image: url("https://images.unsplash.com/photo-1498050108023-c5249f4df085?auto=format&fit=crop&w=300&q=80");
    background-repeat: repeat-y;
    background-size: 180px 120px;
    background-position: top left;
    min-height: 300px;
}
Output
Vertical Repeat

The image repeats from top to bottom.

Background Repeat Values

Value Behavior
repeat Repeats horizontally and vertically
no-repeat Displays the image only once
repeat-x Repeats horizontally
repeat-y Repeats vertically

Simple Explanation

repeat → Repeats the image in both directions.

no-repeat → Shows the image only once.

repeat-x → Repeats the image horizontally.

repeat-y → Repeats the image vertically.

Summary

  • Use background-repeat to control image repetition.
  • no-repeat displays the image once.
  • repeat-x repeats the image horizontally.
  • repeat-y repeats the image vertically.