How to change body background color in HTML?

Member

by sincere , in category: HTML/CSS , 2 years ago

How to change body background color in HTML?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by Ekaterina_90 , 2 years ago

@sincere  Find the “body” CSS selector.  Next, we’ll change the background color of the entire web page using the background-color property.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <style>
      body {
        background-color: blanchedalmond;
      }
      button {
        background-color: blue;
      }
    </style>
  </head>
  <body>
    <button type="button">Click Me!</button>
  </body>
</html>

Member

by alfonzo , a year ago

@sincere 

To change the background color of the body in HTML, you can use the "style" attribute in the opening "body" tag and set the background-color property to the desired color. For example, to set the background color to blue:


You can also use an external stylesheet to define the background color for the body:

1
2
3
4
5
6
7
8
9
  
    body {
      background-color: blue;
    }
  


  


Additionally, you can use CSS shorthand properties to set multiple background properties, such as background-color, background-image, and background-repeat:


In the above example, the background color is set to blue, with a background image of "your-image.jpg". The image is set to not repeat, and is horizontally and vertically centered, and fixed to the viewport (so it stays in the same place as the user scrolls).