Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • 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
  • HTML Tutorial
  • HTML Exercises
  • HTML Tags
  • HTML Attributes
  • Global Attributes
  • Event Attributes
  • HTML Interview Questions
  • HTML DOM
  • DOM Audio/Video
  • HTML 5
  • HTML Examples
  • Color Picker
  • A to Z Guide
  • HTML Formatter
Open In App

HTML DOM Style backgroundColor Property

Last Updated : 30 Jun, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

The backgroundColor property in HTML DOM is used to set or return the background-color of an element.

Syntax:

object.style.backgroundColor
  • It returns the background color of an element.
object.style.backgroundColor ="color|transparent|initial|inherit"
  • It is used to set the background color of an element.

Parameter: There are four parameters accepted by backgroundColor property  

  • color: This property holds the background color.
  • transparent: By default the background color is transparent.
  • initial: Set this property to its default
  • inherit: Inherits the property from its parent element

Return Values: It returns a string value, which represents the background color.

Example 1: In this example, we will use the backgroundColor property in HTML DOM.

HTML
<!DOCTYPE html> <html>    <head>     <title>         Style backgroundColor Property     </title> </head>    <body style="text-align:center">     <h1 style="color:green;">         GeeksForGeeks     </h1>     <h2>         Style backgroundColor Property     </h2>     <button type="button" onclick="geeks()">         Submit     </button>              <script>         /* script to set background color */         function geeks() {             document.body.style.backgroundColor =                 "lightgreen";         }     </script> </body>    </html> 

Output: 

Example 2: In this example, we will use the backgroundColor property in HTML DOM.

HTML
<!DOCTYPE html> <html>  <head>     <title>         Style backgroundColor Property     </title>     <style>         #geeks {             width: 250px;             height: 100px;             background-color: coral;         }     </style> </head>    <body>     <center>         <h1 style="color:green;">             GeeksForGeeks         </h1>         <h2>             DOM Style backgroundColor Property         </h2>         <button onclick="geeks()">Submit</button>         <div id="geeks">             <h1>GeeksForGeeks</h1>         </div>                <script>             function geeks() {                 document.getElementById("geeks").style.backgroundColor =                     "lightgreen";             }         </script>     </center> </body>  </html> 

Output: 

Supported Browsers: The browser supported by DOM style backgroundColor Properties are listed below:  

  • Chrome 1.0 and above
  • Edge 12 and above
  • Internet Explorer 4.0 and above
  • Firefox 1.0 and above
  • Safari 1.0 and above
  • Opera 3.5 and above

M

manaschhabra2
Improve
Article Tags :
  • Misc
  • Web Technologies
  • HTML
  • HTML-DOM
Practice Tags :
  • Misc

Similar Reads

    HTML DOM designMode Property
    The DOM designMode property in HTML is used to specify whether the document is editable or not. It can also be used to set the document editable. Syntax:Set: This property is used to set whether the document is editable or not.document.designMode = "on|off";Get: This property is used to return wheth
    2 min read
    HTML DOM Style borderCollapse Property
    The DOM Style borderCollapse property in HTML is used to set or return whether the border of the table collapsed into a single border or not. Syntax: It is used to return the borderCollapse property.object.style.borderCollapse It is used to set borderCollapse property.object.style.borderCollapse = "
    2 min read
    HTML DOM Style borderBottom Property
    The DOM style borderBottom property is used to set or return the three different border-bottom properties such as border-bottom-width, border-bottom-style, and border-bottom-color of an element. Syntax: It returns the borderBottom Property.object.style.borderBottomIt is used to set the borderBottom
    2 min read
    HTML DOM Style color Property
    The DOM style color property is used to set or return the color of the text. Syntax: It is used to set the color property.object.style.colorIt is used to return the color property.object.style.color = "color|initial|inherit" Return Values: It returns a string value that represents a text-color of an
    1 min read
    HTML DOM cookie Property
    Almost every website stores cookies (small text files) on the user's computer for recognition and to keep track of his preferences. DOM cookie property sets or gets all the key/value pairs of cookies associated with the current document.Getting all the Cookies: The document.cookie method returns a s
    3 min read
    HTML DOM isId Property
    The isId Property contains a boolean value that returns a true if the Element has an attribute type of ID, otherwise, it returns a false or undefined value. This Property is used for read-only. Syntax: attribute.isId Return Value: It returns a Boolean value i.e. true if the attribute type is ID, els
    2 min read
    HTML DOM createElement() Method
    In an HTML document, the document.createElement() is a method used to create the HTML element. The element specified using elementName is created or an unknown HTML element is created if the specified elementName is not recognized. Syntaxlet element = document.createElement("elementName");In the abo
    2 min read
    HTML DOM hasFocus() Method
    In HTML document, the document.hasfocus() the method is used for indicating whether an element or document has the focus or not. The function returns a true value if the element is focused otherwise false is returned. This method can be used to determine whether the active element is currently in fo
    2 min read
    HTML DOM removeNamedItem() Method
    The removeNamedItem() method in HTML is used to remove the node with the specified name in a namednode object.Syntax: namednode.removeNamedItem( nodename )Parameter: The removeNamedItem() contains only one parameter nodename that is described below. nodename: This method accepts a single parameter n
    2 min read
    HTML DOM domain Property
    The domain Property is used to return the domain name of the website server that is loaded or running in the current document. Syntax:document.domain Note: This property has been DEPRECATED and is no longer recommended.Return Value: It returns the string value representing the website's domain name
    2 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