Open In App

How to set multiple background images using CSS?

The multiple background images for an element can be put in the HTML page using CSS. Use CSS background property to add multiple background images for an element in any pattern and use other CSS property to set the height and width of the images.

The used background property are listed below:



Example 1: Use individual background property to specify the multiple background images.




<!DOCTYPE html>
<html>
  
<head>
    <style
        body { 
            text-align:center;
        }
        h1 { 
            color: green; 
        
        #GFG {
            background-image: 
  
            background-position: center, center;
            background-repeat: no-repeat, no-repeat;
            background-size: 400px 200px, 500px 400px;
            padding:25px;
            height:400px;
        }
    </style>
</head>
  
<body
    <div id = "GFG">
          
        <h1>GeeksforGeeks</h1>
          
        <h2>Set Multiple Backgrounds</h2>
          
        <p>
            Element contains two background images
        </p>
    </div>
</body>
  
</html>                                

Output:

Example 2: Use background shorthand property to specify the multiple background images.




<!DOCTYPE html>
<html>
  
<head>
    <style
        h1 { 
            color: green; 
        
        body { 
            text-align: center; 
        
        #GFG {
            background: 
            center no-repeat, 
            center no-repeat;
              
            background-size:400px 200px, 400px 400px;
            padding:25px;
            height:400px;
        }
    </style>
</head>
  
<body
    <div id = "GFG">
          
        <h1>GeeksforGeeks</h1>
          
        <h2>Set Multiple Backgrounds</h2>
          
        <p>
            Element contains two background images
        </p>
    </div>
</body>
  
</html>                    

Output:




Article Tags :