CSS background-image Property

Beginner
⏱️ 7 min read
📚 Updated: Jun 2026
🎯 4 Examples
Backgrounds & Images

What You’ll Learn

The background-image property lets you place images and gradients behind an element’s content. It is one of the most useful tools for hero sections, cards, textures, and decorative backgrounds.

01

Image Backgrounds

Use url() for files.

02

Gradients

Linear and radial fills.

03

Multiple Layers

Stack backgrounds.

04

none Default

No image by default.

05

Related Props

size, repeat, position.

06

With color

Combine with background-color.

Definition and Usage

The background-image CSS property sets one or more background images for an element. The image is painted behind the content, borders, and padding according to other background properties.

You can use regular image files with url(), CSS gradients, or several layered backgrounds separated by commas. This makes it possible to build rich visual designs without extra HTML elements.

💡
Beginner Tip

Start with a simple linear-gradient(). Once that works, try background-size and background-repeat to control how the image fits the element.

📝 Syntax

Apply background-image using a single image value or a comma-separated list:

syntax.css
selector {

  background-image: <image>;

}

Basic Example

background-image.css
.hero {

  background-image: url("hero.jpg");

  background-size: cover;

  background-position: center;

}

Multiple Background Layers

layered-background.css
.panel {

  background-image:

    linear-gradient(rgba(0,0,0,0.45), rgba(0,0,0,0.45)),

    url("photo.jpg");

}

Syntax Rules

  • The initial value is none.
  • Separate multiple layers with commas. The first value is painted on top.
  • Gradients count as images and work directly in background-image.
  • Use companion properties like background-size, background-repeat, and background-position to control layout.
  • background-color fills any transparent areas behind the image.

⚡ Quick Reference

QuestionAnswer
Initial valuenone
Applies toAll elements
InheritedNo
AnimatableNo
Common useHero banners, textures, gradients, photo backgrounds

Default Value

The initial value of background-image is none. That means no background image is painted unless you set one explicitly.

💎 Property Values

These are the most common background-image values beginners use.

ValueExampleMeaning
nonebackground-image: none;No background image is applied
url()background-image: url("photo.jpg");Loads an image file as the background
linear-gradient()background-image: linear-gradient(135deg, #2563eb, #9333ea);Creates a straight color transition
radial-gradient()background-image: radial-gradient(circle, #38bdf8, transparent);Creates a circular or elliptical gradient
Repeating gradientsbackground-image: repeating-linear-gradient(45deg, #fde68a, #fde68a 10px, #f59e0b 10px 20px);Creates a repeating pattern effect
Multiple layersbackground-image: linear-gradient(...), url("photo.jpg");Stacks more than one background layer
linear-gradient()

Great for hero sections, buttons, and smooth color transitions.

Very common in modern CSS layouts.

url()

Uses image files such as JPG, PNG, SVG, or WebP.

Pair with background-size: cover;

radial-gradient()

Useful for spotlight, glow, and circular highlight effects.

Works well on dark backgrounds.

repeating-*

Creates stripes, grids, and other repeating patterns.

No image file required.

none

The default value. Only background-color shows if set.

Removes a background image.

background-image vs background-color

PropertyPaintsBest for
background-imageImages, gradients, and layered backgroundsHero photos, textures, decorative fills
background-colorA solid color behind the contentSimple panels, cards, and fallback fills

👀 Live Preview

These panels use different background-image values:

linear-gradient
radial-gradient
repeating pattern

Gradients and patterns are valid background images, not just photo files.

Examples Gallery

Try background-image with linear gradients, radial gradients, url() images, and multiple layered backgrounds.

📚 Gradient Backgrounds

Gradients are one of the easiest ways to start learning background-image.

Example 1 — Linear Gradient Hero

Create a colorful hero section using a straight gradient background.

linear-gradient.css
.hero {

  background-image: linear-gradient(135deg, #2563eb, #9333ea);

  background-size: cover;

  min-height: 70vh;

}
Try It Yourself

How It Works

The browser treats the gradient as an image and paints it behind the hero content.

Example 2 — Radial Gradient Spotlight

Use a radial gradient to create a soft glow effect on a dark section.

radial-gradient.css
.card {

  background-color: #0f172a;

  background-image: radial-gradient(circle at top, #38bdf8, transparent 55%);

}
Try It Yourself

How It Works

The radial gradient fades from a bright center color to transparent, creating a spotlight over the dark base color.

🎨 Image Files & Layers

Use url() for real image files and stack multiple background layers when needed.

Example 3 — Background Image with url()

Load an image file as the element background and control its size with background-size.

url-background.css
.background-example {

  width: 300px;

  height: 200px;

  background-image: url("example.jpg");

  background-size: cover;

}
Try It Yourself

How It Works

The browser loads the image from the path inside url() and paints it behind the element. Use background-size: cover; to fill the box cleanly.

Example 4 — Multiple Background Layers

Stack an overlay gradient on top of another gradient for richer hero sections.

layered-background.css
.hero {

  background-image:

    linear-gradient(rgba(15, 23, 42, 0.55), rgba(15, 23, 42, 0.55)),

    linear-gradient(135deg, #0ea5e9, #6366f1);

  background-size: cover;

}
Try It Yourself

How It Works

The first background layer is painted on top. Here, the dark overlay softens the colorful gradient beneath it.

🧠 How background-image Works

1

You choose an image source

Use url(), a gradient function, or multiple comma-separated layers.

Image value
2

The browser paints it behind content

The image appears in the element’s background area, underneath text and child elements.

Rendering
3

Other background properties shape it

Use background-size, background-repeat, and background-position to control fit and placement.

Layout
=

Rich visual backgrounds

You can create hero banners, textures, overlays, and decorative sections with CSS alone.

Universal Browser Support

background-image is supported in all modern browsers, including gradients and multiple background layers.

Baseline · All browsers

Add background images everywhere

Chrome, Firefox, Safari, Edge, and Opera all support url(), gradients, and layered backgrounds.

99% Universal support
Google Chrome1+ · Desktop & Mobile
Full support
Mozilla Firefox3.6+ · Desktop & Mobile
Full support
Apple Safari1+ · macOS & iOS
Full support
Microsoft Edge12+ · All versions
Full support
Opera3.5+ · Modern versions
Full support

Fallback behavior

If an image fails to load, the browser can still show background-color behind the element.

💻
Broken image paths No image appears · Use a fallback background-color
Fallback
background-image property 99% supported

Bottom line: Use background-image confidently, and always provide a sensible fallback color when using photo backgrounds.

Conclusion

The background-image property is a flexible way to add visual interest to your layouts. You can use photo files, gradients, repeating patterns, and multiple layered backgrounds to build modern designs with CSS.

Start with a simple gradient, then explore url(), layered overlays, and companion properties like background-size and background-position.

💡 Best Practices

✅ Do

  • Use gradients when you want reliable demo and production results
  • Add a fallback background-color behind photo backgrounds
  • Use background-size: cover; for full-area hero images
  • Optimize image file size for faster page loading
  • Keep text readable over busy background images

❌ Don’t

  • Confuse background-image with background-color
  • Forget that the first layer in a comma-separated list appears on top
  • Use huge unoptimized images for small elements
  • Rely on background images alone for important content meaning
  • Ignore mobile performance when using large photo backgrounds

Key Takeaways

Knowledge Unlocked

Five things to remember about background-image

Use these points when adding images and gradients to your layouts.

5
Core concepts
🎨02

Gradients Count

Valid background images.

Values
🖼️03

Multiple Layers

Comma-separated list.

Layers
04

none Default

No image unless set.

Default
🛠05

Companion Props

size, repeat, position.

Layout

❓ Frequently Asked Questions

The background-image property sets one or more background images for an element. These can be image files using url(), gradients, or a combination of layered backgrounds.
The initial value is none, which means no background image is painted on the element.
Yes. Functions such as linear-gradient(), radial-gradient(), and repeating-linear-gradient() are common background-image values.
Yes. Separate multiple background layers with commas. The first image in the list is painted on top.
background-image paints images or gradients. background-color paints a solid color behind the content. They are often used together.

Practice in the Live Editor

Open the HTML editor, add gradients and background images, and preview the result instantly.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful