💡 Tip: Login now to track your course progress and unlock your downloadable certificates instantly!

CSS Background Image

The CSS Background Image property is used to set an image as the background of an HTML element.

It allows you to enhance the visual design of a webpage by adding images behind content such as:

  • Entire page (body)
  • Sections (div)
  • Headers

You can also control how the image behaves using additional background properties.

Syntax
selector {
    background-image: url("image.jpg");
}
Example
body {
    background-image: url("background.jpg");
}

👉 This sets an image as the background of the page.

Attributes

PropertyDescriptionExample
background-imageSets background imagebackground-image: url(“img.jpg”);
background-repeatControls image repetitionbackground-repeat: no-repeat;
background-sizeDefines image sizebackground-size: cover;
background-positionSets image positionbackground-position: center;
background-attachmentDefines scrolling behaviorbackground-attachment: fixed;

Example

Complete CSS Example for Background Image
<!DOCTYPE html>
<html>
<head>
    <title>CSS Background Image</title>
    <style>
        body {
            background-image: url("https://picsum.photos/500/500?grayscale");
            background-repeat: no-repeat;
            background-size: cover;
            background-position: center;
        }
        h1 {
            color: white;
            text-align: center;
        }
        p {
            color: yellow;
            text-align: center;
        }
    </style>
</head>
<body>

    <h1>Background Image Example</h1>
    <p>This page uses a background image.</p>

</body>
</html>

Output

Browser Output

The page will display a full-screen background image
The image will not repeat
The image will be centered and cover the entire screen
Text will appear on top of the image

Browser Support

Chrome
Chrome
Firefox
Firefox
Edge
Edge
Safari
Safari
Opera
Opera
IE
IE9+
✅Yes✅Yes✅Yes✅Yes✅Yes✅Yes

Notes

  • Always use url() to define the image path
  • Use background-size: cover for full-screen effect
  • Use no-repeat to prevent image repetition
  • Ensure text is readable over the background image
  • Optimize images for faster page loading

Conclusion

CSS Background Image allows you to create visually rich and engaging web pages. By combining it with other background properties, you can control how images appear and behave, resulting in professional and modern designs.

Sign In Form

Use your email and password to sign in

Provide your email and we will send you a password reset link.

Don’t have an account, signup here : 

HTML5 & CSS3

Tools and Tutorials

Registration Form

Signup to track your record and much more.

We have sent you an email with a registration link. Please click the link to verify your email address, or enter the 6-digit OTP provided in the email.

Didn't receive the OTP. Regenerate OTP Resend