Changing Background Color using bgcolor attribute
HTML allows you to alter the background color of an element using the bgcolor
attribute. However, itās crucial to note that the bgcolor
attribute is considered deprecated in HTML5, and itās recommended to use CSS for styling purposes instead.
Changing Background Color using bgcolor attribute Syntax:
bgcolor="color_name"
Changing Background Color using bgcolor attribute Example:
Here, we sets the background color of the body to light green using the bgcolor attribute.
<html>
<head>
<title>Background Change using bgcolor attribute Example</title>
</head>
<body bgcolor="lightgreen">
<h1>
Hello reader my name is sachin
Welcome to GeekforGeeks
</h1>
</body>
</html>
Output:
Changing Background Color using bgcolor attribute Example Explanation:
- The HTML file defines the structure of the webpage.
- Set to light green using the bgcolor attribute within the <body> tag.
How to change Background Color in HTML ?
The background color in HTML refers to the color displayed behind the content of the webpage.to change it, CSS is used, with various approaches available to change the background color. in which we define the background color property within a CSS rule, specifying a color value such as a name, hexadecimal code, RGB, or HSL value. Apply this rule to the desired HTML element.
There are three methods to change the background color of a document:
Table of Content
- Changing Background Color using bgcolor attribute
- Changing Background Color using an Inline CSS
- Changing Background Color using Internal CSS
- Changing Background Color using External CSS