Open In App

How to use the background Property in CSS ?

Last Updated : 16 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The background property in CSS is a comprehensive shorthand property that allows you to set various background-related properties for an element. It’s used to control the background color, image, position, size, and other related aspects.

Syntax:

/* Example of using the background property */
.element
{
background: [background-color] [background-image]
[background-repeat] [background-attachment]
[background-position];
}

The background Property Values:

The table below illustrates CSS background properties and their respective descriptions.

CSS Property Description
background-color Sets the background color using color names, hex codes, RGB values, etc.
background-image Specifies the background image using a URL or gradients.
background-repeat Defines how the background image should be repeated.
background-attachment Sets whether the background image is fixed or scrolls with the content.
background-position Determines the starting position of the background image.

Features:

  • The background property combines multiple background-related properties into a single line, improving code readability.
  • Values can be specified in any order, but it’s common to follow the order mentioned above.
  • You can use the background property to create gradient backgrounds as well.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads