Open In App

Difference between background and background-color

Improve
Improve
Like Article
Like
Save
Share
Report
  1. Background Property The background property in CSS is very commonly used and contains many variants. The background property consists of all the following properties:

html




<style>
    h1 {
        background-color: blue;
    }
</style>
 
<body>
    <h1>
     Geeksforgeeks
</h1>
</body>


  • Output:
  • Example: 

html




<style>
    body {
        background-image: url(gfgpolaroidimagefunction.png);
    }
</style>
 
<body>
    <h1>
Geeksforgeeks
</h1>
</body>


  • Output:
  1. Background-color Property: The background-color property in CSS is used to specify the background color of an element. On the other hand, if you only use “Background:” Property, you can either specify it’s valued as an image URL or as a color code or specify the value of each background property in the below-given order.
  2. Syntax:
element {
    background-color property
}
  1. Example: 

html




<!DOCTYPE html>
<html>
    <head>
        <title>background-color property</title>
        <style
            body {
                text-align:center;
                background-color:green;
            }
            h1 { 
                color:white;
                background-color:blue;
            
            h2 {
                color:white;
                background-color:black;
            }
        </style
    </head>
    <body
        <h1>Geeksforgeeks </h1
        <h2>background-color: color_name;</h2>     
    </body
</html>


  1. Output:


Last Updated : 21 Feb, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads