HTML Style Background Color Property | Style Background Color Tutorial by WDH

HTML Style Background Color Property


To set the background color in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <body> tag, with the CSS property background-color. HTML5 do not support the <body> tag bgcolor attribute, so the CSS style is used to add background color. The bgcolor attribute deprecated in HTML5.

Just keep in mind, the usage of style attribute overrides any style set globally. It will override any style set in the HTML <style> tag or external style sheet.

Example

You can try to run the following code to set the background color in HTML −


 

<!DOCTYPE html> <html> <head> <title>HTML Backgorund Color</title> </head> <body style="background-color:grey;"> <h1>Products</h1> <p>We have developed more than 10 products till now.</p> </body> </html>

Output