css
  1. css-background-repeat

CSS Background Repeat

The CSS background-repeat property is used to control whether a background image should be repeated horizontally and/or vertically on a webpage.

Syntax

background-repeat: repeat|repeat-x|repeat-y|no-repeat|initial|inherit;
  • repeat: The background image will be repeated both horizontally and vertically as necessary to fill the container.
  • repeat-x: The background image will be repeated horizontally only.
  • repeat-y: The background image will be repeated vertically only.
  • no-repeat: The background image will not be repeated.
  • initial: Sets the property to its default value.
  • inherit: Inherits the property from its parent element.

Example

Here's an example of using background-repeat in CSS:

div {
    background-image: url("https://static.additionalsheet.com/images//others/lucy.jpg");
    background-repeat: repeat-x;
}
Try Playground

Explanation

The background-repeat property controls how the background image should be displayed if it is smaller than the container. The default value for background-repeat is repeat, which tells the browser to repeat the image both horizontally and vertically as many times as necessary to fill the container.

Use

The background-repeat property can be used to control the appearance of a website's background image. This property is useful for ensuring that the background image looks the way you want it to, regardless of the size of the container.

Important Points

  • The background-repeat property affects only the position of the background image, not the actual image itself.
  • The default value for background-repeat is repeat.
  • You can set different background-repeat values for different elements on the same webpage.
  • To prevent an image from repeating, use the value no-repeat.

Summary

The CSS background-repeat property controls how a background image should be repeated on a webpage. With its easy-to-use syntax and a variety of possible values, this property is a powerful tool for customizing the appearance of a webpage's background.

Published on: