Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • CSS Tutorial
  • CSS Exercises
  • CSS Interview Questions
  • CSS Selectors
  • CSS Properties
  • CSS Functions
  • CSS Examples
  • CSS Cheat Sheet
  • CSS Templates
  • CSS Frameworks
  • Bootstrap
  • Tailwind
  • CSS Formatter
Open In App
Next Article:
CSS Preprocessor SASS
Next article icon

How to set multiple background images using CSS?

Last Updated : 08 Feb, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report

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:

  • background-image: url(), url(), …; This property is used to set one or more background images to the element, separated by commas.
  • background-position: right bottom, left top; This property is used to set the position of different images in the page. It set the initial position for each background image.
  • background-repeat: no-repeat, repeat; This property is used to set the repetition of the background images. The background image can be repeated along the horizontal and vertical axis.
  • background-size: cover|contain|30%|200px 100px; This property is used to set the size of the element background image.

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: 
url(https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-6-1.png), 
url(https://media.geeksforgeeks.org/wp-content/uploads/backgroundimage-1.png);
  
            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: 
url(https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-6-1.png)
            center no-repeat, 
url(https://media.geeksforgeeks.org/wp-content/uploads/backgroundimage-1.png) 
            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:



Next Article
CSS Preprocessor SASS

S

SHUBHAMSINGH10
Improve
Article Tags :
  • CSS
  • CSS-Misc

Similar Reads

  • How to make an image center-aligned (vertically & horizontally) inside a bigger div using CSS ?
    We will know how to center-align the image in a div tag using CSS & will also understand its implementation through the example. Given an image, we need to set the image that align to the center (vertically and horizontally) inside a bigger div. But first let's create a basic structure, in which
    2 min read
  • What does the CSS rule “clear: both” do?
    The clear property is used to specify which side of floating elements are not allowed to float. It sets or returns the position of the element about floating the objects. The "clear: both" means floating the elements are not allowed to float on both sides. It is used when no need for any element to
    1 min read
  • How to Break Line Without using <br> Tag in HTML / CSS?
    Breaking lines in HTML without <br> tags can be achieved using block-level elements such as <div> or <p> combined with CSS properties like display: block; or display: inline-block; and others. These elements naturally wrap text or content, facilitating clean and structured layout d
    2 min read
  • Set the size of background image using CSS ?
    Setting the size of a background image using CSS allows you to control how the image fits within an element. By using the background-size property, you can specify the width and height, ensuring the image scales appropriately for responsive design. Syntax: background-size: width height;Note: If the
    2 min read
  • What is Greater-than Sign (>) Selector in CSS?
    In CSS, the greater than sign (>) is known as the child combinator selector. It is used to style elements that have a specific parent. Unlike other selectors, it only targets direct children of an element, meaning it only looks one level down in the HTML structure. How the Child Combinator Select
    2 min read
  • How to Select all Child Elements Recursively using CSS?
    Here are three methods to achieve to Select all Child Elements Recursively using CSS: 1. Using the Universal Selector (*)The universal selector applies styles to all child elements within a parent recursively. [GFGTABS] HTML <html> <head> <style> .parent * { color: blue; font-weigh
    3 min read
  • How to style a checkbox using CSS ?
    Styling a checkbox using CSS involves customizing its appearance beyond the default browser styles. This can include changing the size, color, background, and border, and adding custom icons or animations. Techniques often involve hiding the default checkbox and styling a label or pseudo-elements fo
    3 min read
  • What is the difference between “word-break: break-all” versus “word-wrap: break-word” in CSS ?
    The word-break property in CSS is used to specify how a word should be broken or split when reaching the end of a line. The word-wrap property is used to split/break long words and wrap them into the next line. Difference between the "word-break: break-all;" and "word-wrap: break-word;" word-break:
    2 min read
  • How to make div height expand with its content using CSS ?
    When designing a webpage, ensuring that a div adjusts its height according to its content is important for creating a flexible and responsive layout. By using CSS, you can easily make a div adapt to varying content sizes, which is particularly useful when dealing with dynamic or unpredictable conten
    3 min read
  • How to float three div side by side using CSS?
    Floating three div elements side by side using CSS means aligning them horizontally in a row. This is done by applying float: left; to each div, which moves them to the left of the parent container, allowing them to sit next to each other. These are the following ways to solve this problem: Table of
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences