CSS background-image Property

The CSS background-image property sets one or more background images for an element. It allows you to specify the image URL and combine it with other background properties to control its position, size, repeat behavior, and more, enhancing the visual design of web pages.

Syntax

background-image: url('url')|none|initial|inherit;

Property Values

Values

Description

url(‘url’)

This specifies the URL of the image. To specify the URL of more than one image then separate the URLs using a comma.

nope

This is the default case where no image can be displayed.

initial

It is used to set the property to its default value.

inherit

It inherits the property from its parent element.

The background-image property can also be used with the following values:

Values

Desccriptions

linear-gradient()

It is used to set the linear-gradient background-image that is defined at least 2 color from top to bottom.

radial-gradient()

It is used to set the radial-gradient background-image that is defined at least 2 color from center to edge.

Example 1: This example illustrates the background-image property by setting the url value as url.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>background-image property</title>
    <style>
        body {
            background-image: url(
"https://media.w3wiki.net/wp-content/uploads/rk.png");
        }

        h1,
        h3 {
            color: green;
        }

        body {
            text-align: center;
        }
    </style>
</head>

<body>
    <h1>w3wiki</h1>
    <h3>background-image:url;</h3>
    <div>
        w3wiki: A computer science portal for Beginner
    </div>
</body>

</html>

Output:

Example 2: This example illustrates the background-image property by setting the url value as none.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>background-image property</title>
    <style>
        body {
            background-image: url(
"https://media.w3wiki.net/wp-content/uploads/rk.png") none;
        }

        h1,
        h3 {
            color: green;
        }

        body {
            text-align: center;
        }
    </style>
</head>

<body>
    <h1>w3wiki</h1>
    <h3>background-image:url none;</h3>
    <div>
        w3wiki: A computer science portal for Beginner
    </div>
</body>

</html>

Output:

Example 3: This example illustrates the background-image property by setting the url value as initial.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>CSS background-image property</title>
    <style>
        body {
            background-image: url(
"https://media.w3wiki.net/wp-content/uploads/rk.png") initial;
        }

        h1,
        h3 {
            color: green;
        }

        body {
            text-align: center;
        }
    </style>
</head>

<body>
    <h1>w3wiki</h1>
    <h3>CSS background-image:url initial;</h3>
</body>

</html>

Output:

DOM background Image Property

The HTML DOM Style backgroundImage Property can be used to set or return the background image of an element.

Supported Browsers

The browser supported by background-image Property are listed below: 



Contact Us