CSS Guide · 2026

CSS Background Properties

Complete guide with live interactive demos — colours, images, gradients, patterns, blending and creative visual effects, with practical code snippets.

What Are CSS Background Properties?

CSS (Cascading Style Sheets) provides powerful background properties that allow developers to customize the appearance of HTML elements — background colours, images, gradients, patterns and creative visual effects.

Whether you are a beginner learning CSS or an experienced frontend developer, understanding CSS Background Properties is essential for creating attractive, modern and responsive websites.

CSS Background Properties are used to control the background appearance of HTML elements. They allow you to apply colours, images, gradients and different visual effects to elements such as sections, containers, buttons, cards and entire web pages.

About the live demos below: every demo uses a self-contained CSS-generated placeholder image — a blue square with a yellow circle and a red corner mark — so you can clearly see how each property affects positioning, repeating, sizing and blending. No external files are loaded.

CSS background-color

The background-color property is used to set the background colour of an HTML element. CSS supports different colour formats, including colour names, HEX, RGB, RGBA, HSL and HSLA.

Example

.box {
  background-color: #2563eb;
  color: white;
  padding: 20px;
}

Different Colour Values

.box1 { background-color: red; }
.box2 { background-color: #2563eb; }
.box3 { background-color: rgb(0, 128, 255); }
.box4 { background-color: rgba(0, 128, 255, 0.5); }
.box5 { background-color: transparent; }
Live Demo
hotpink
#2563eb
rgb(0,128,255)
rgba(0,128,255,.5)
hsla(300,80%,50%,.6)
transparent

Common Values

  • red — sets a red background.
  • #2563eb — uses HEX colour notation.
  • rgb() — defines a colour using RGB values.
  • rgba() — defines an RGB colour with transparency.
  • hsl() — defines colour using Hue, Saturation and Lightness.
  • transparent — creates a transparent background.

CSS background-image

The background-image property allows you to add an image or gradient to an HTML element. It is commonly used for website banners, hero sections, landing pages and decorative backgrounds.

Example

.hero {
  background-image: url("background.jpg");
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
}

Using a Linear Gradient

.hero {
  background-image: linear-gradient(
    to right,
    #2563eb,
    #9333ea
  );
}
Live Demo
url("image.jpg")
linear-gradient
radial-gradient
conic-gradient
You can also use radial-gradient() and conic-gradient() to create different background effects — no image files required.

CSS background-origin

The background-origin property specifies the positioning area from which a background image is placed. It has three main values:

ValueDescription
border-boxBackground positioning starts from the border edge.
padding-boxBackground positioning starts from the padding edge (default).
content-boxBackground positioning starts from the content edge.

Example

.box {
  border: 10px dashed purple;
  padding: 25px;
  background-image: url("image.jpg");
  background-origin: content-box;
  background-repeat: no-repeat;
}
Live Demo
padding-box default
border-box starts at border
content-box starts at content
Useful when you need precise control over background image placement inside an element with thick borders or padding.

CSS background-repeat

The background-repeat property controls whether and how a background image repeats inside an element.

ValueDescription
repeatRepeats the image horizontally and vertically (default).
no-repeatDisplays the image only once.
repeat-xRepeats the image horizontally.
repeat-yRepeats the image vertically.
spaceDistributes repeated images with spacing.
roundAdjusts image sizes to fit without gaps.
.box {
  background-image: url("pattern.png");
  background-repeat: repeat-x;
}
Live Demo
no-repeat
repeat
repeat-x
repeat-y
space
round

CSS background-clip

The background-clip property determines how far the background extends within an element.

Available Values

  • border-box
  • padding-box
  • content-box
  • text
h1 {
  background: linear-gradient(90deg, red, blue, cyan);
  color: transparent;
  background-clip: text;
  -webkit-background-clip: text;
}
Live Demo
background-clip: border-box
background-clip: padding-box
background-clip: content-box
GRADIENT TEXT

The background-clip: text technique creates gradient-coloured text by displaying the background through the text characters. It is commonly used for modern headings, logos and creative website designs.

CSS background-position

The background-position property controls the position of a background image inside an element. You can position an image using keywords, percentages or pixel values.

ValuePosition
left topTop-left corner
right topTop-right corner
centerCenter position
left bottomBottom-left corner
right bottomBottom-right corner
10% 40%Percentage-based position
50px 100pxPixel-based position
right 20px bottom 30px4-value syntax with offsets
.box {
  background-image: url("image.jpg");
  background-repeat: no-repeat;
  background-position: center;
}

/* Separate axes */
.box {
  background-position-x: right;
  background-position-y: top;
}
Live Demo
left top
left center
left bottom
right top
right center
right bottom
center top
10% 40%
50px 100px
center
right 20px bottom 30px
calc(100% − 20px) center

CSS background-attachment

The background-attachment property determines how a background image behaves when the page or element is scrolled.

ValueDescription
scrollBackground scrolls normally with the page (default).
fixedBackground remains fixed relative to the viewport.
localBackground scrolls with the element's content.
body {
  background-image: url("background.jpg");
  background-attachment: fixed;
  background-position: center;
  background-size: cover;
}
Live Demo — scroll inside each box

fixed

Scroll inside — image stays fixed.

Scroll inside — image stays fixed.

Scroll inside — image stays fixed.

Scroll inside — image stays fixed.

Scroll inside — image stays fixed.

Scroll inside — image stays fixed.

scroll (default)

Scroll — image scrolls with page.

Scroll — image scrolls with page.

Scroll — image scrolls with page.

Scroll — image scrolls with page.

Scroll — image scrolls with page.

Scroll — image scrolls with page.

local

Scroll inside — image moves with content.

Scroll inside — image moves with content.

Scroll inside — image moves with content.

Scroll inside — image moves with content.

Scroll inside — image moves with content.

Scroll inside — image moves with content.

fixed can create attractive parallax-like scrolling effects, but may behave inconsistently on some mobile browsers.

CSS background-size

The background-size property controls the width and height of a background image. It helps you fit images into different containers without changing the HTML structure.

ValueDescription
autoUses the image's original dimensions (default).
coverCovers the entire container.
containFits the entire image inside the container.
100% 100%Stretches the image to the container dimensions.
50pxSets the image width to 50px, keeping aspect ratio.
200px 100pxSets a specific width and height.
.hero {
  background-image: url("banner.jpg");
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
}
Live Demo
auto
cover
contain
70%
50px
200px 100px

Difference Between Cover and Contain

cover

Fills the entire container, but some parts of the image may be cropped.

contain

Displays the complete image, but empty spaces may remain inside the container.

CSS background-blend-mode

The background-blend-mode property controls how multiple background layers blend together. It is useful for creating creative colour effects, image overlays and modern website backgrounds.

.box {
  background-image: url("image.jpg"),
                    linear-gradient(red, blue);
  background-blend-mode: multiply;
}
Live Demo — image + gradient blend
normal
multiply
screen
overlay
darken
lighten
color
hue
saturation
luminosity
hard-light

CSS Background Shorthand Property

The background shorthand property allows you to combine multiple background-related settings into a single declaration. Instead of writing each property separately, you can use one shorter CSS statement.

Longhand Example

.box {
  background-color: cyan;
  background-image: url("image.jpg");
  background-repeat: no-repeat;
  background-position: center;
  background-attachment: scroll;
  background-size: cover;
}

Shorthand Example

.box {
  background: cyan url("image.jpg") no-repeat center / cover scroll;
}
Live Demo
background: url("image") cyan …
background: linear-gradient(…) black …
Using shorthand properties makes your CSS shorter, cleaner and easier to maintain.

CSS Multiple Background Images

CSS allows you to apply multiple background images to a single HTML element. You can separate different background layers using commas.

.box {
  background-image:
    url("image1.png"),
    url("image2.png"),
    url("image3.png");
  background-position: top left, top right, bottom center;
  background-repeat: no-repeat;
  background-size: 100px, 100px, 150px;
}
Live Demo — 5 stacked layers
The first background image is displayed on the top layer, with subsequent images layered below. Multiple backgrounds are useful for creating complex banners, decorative sections and advanced UI designs.

CSS Multiple Gradient Backgrounds

CSS also allows you to combine multiple gradients in a single element. You can use linear, radial and conic gradients together to create colourful background designs.

.box {
  background:
    linear-gradient(45deg, red, transparent),
    linear-gradient(135deg, blue, cyan),
    radial-gradient(circle, yellow, transparent);
}
Live Demo — 5 gradients with blend mode
This technique is useful for creating modern backgrounds without downloading any additional image files.

CSS Background Transition Effects

CSS transitions allow you to animate background-related properties smoothly when an element changes state. For example, you can move a background image from left to right when a user hovers over an element.

.box {
  height: 200px;
  background-image: url("image.jpg");
  background-repeat: no-repeat;
  background-size: 100px;
  background-position: left center;
  transition: background-position 0.6s ease,
              background-size 0.6s ease;
}

.box:hover {
  background-position: right center;
  background-size: 160px;
}
Live Demo — hover / focus the box
Hover or focus me 👆

This creates a smooth background animation when the user interacts with the element.

Practical Uses of CSS Background Properties

CSS Background Properties are widely used in modern web development. Some common applications include:

  • Website Banners: create attractive hero sections with background images and gradients.
  • Landing Pages: design colourful and professional page backgrounds.
  • Cards & Containers: add background colours, images and patterns.
  • Buttons: create gradient backgrounds and hover effects.
  • Portfolio Websites: make personal websites more visually appealing.
  • Background Animations: add smooth visual effects using CSS transitions.
  • Responsive Designs: adjust background images for different screen sizes.
  • Text Effects: create gradient text using background-clip: text.

Best Practices for Using CSS Background Properties

Follow these tips to create better website designs and maintain clean CSS code:

  • Use background-size: cover for full-width hero sections.
  • Use background-repeat: no-repeat when an image should appear only once.
  • Choose background colours that provide sufficient text contrast.
  • Optimize background images to improve website loading speed.
  • Use CSS gradients when you do not need an actual image.
  • Avoid unnecessarily large background images.
  • Test background behaviour on mobile devices and desktop screens.
  • Use shorthand properties when they improve code readability.

Frequently Asked Questions (FAQs)

Q1. What are CSS Background Properties?

CSS Background Properties are used to customize the background of HTML elements with colours, images, gradients and different visual effects.

Q2. How do I add a background image in CSS?

You can use the background-image property:

body {
  background-image: url("background.jpg");
}
Q3. What is the difference between background-size: cover and contain?

cover fills the entire container and may crop parts of the image, while contain displays the complete image and may leave empty spaces.

Q4. How do I prevent a background image from repeating?

Use the following CSS:

.box {
  background-repeat: no-repeat;
}
Q5. Can I use multiple background images in CSS?

Yes. CSS supports multiple background images using comma-separated values in the background or background-image property.

Q6. What is the purpose of background-blend-mode?

It controls how different background layers blend together to create visual effects.

Q7. Which CSS background property is used to control image position?

The background-position property controls the horizontal and vertical position of a background image.

Q8. Can CSS backgrounds use gradients without images?

Yes. CSS provides linear-gradient(), radial-gradient() and conic-gradient() functions to create backgrounds without external image files.

Conclusion

CSS Background Properties are an important part of modern web design. They give developers complete control over the appearance of HTML elements by allowing them to use colours, images, gradients, blending effects and animations.

By understanding properties such as background-color, background-image, background-size, background-position, background-repeat and background-blend-mode, you can create attractive and responsive website designs.

Practice the examples in this guide and experiment with different combinations to improve your CSS skills.

Keep Learning, Keep Coding! 🚀