How to add background color in HTML?

Member

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

How to add background color in HTML?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by Ekaterina_90 , 2 years ago

@kevon  You can add a background color for an HTML document by adding style="background-color:" to the <body> element.


1
2
3
4
5
6
7
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
  </head>
  <body style="background-color: pink"></body>
</html>

Member

by madalyn , a year ago

@kevon 

To add background color to a webpage in HTML, you can use the CSS (Cascading Style Sheets) style attribute. You can use the background-color property to specify the color you want to apply to the background of an HTML element. Here's an example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
	My Webpage
	
		body {
			background-color: #f2f2f2;
		}
	


	Welcome to My Webpage
	This is a sample text.



In this example, we've set the background color of the body element to light gray (#f2f2f2). You can replace this with any other color code or keyword that you prefer.