JavaScript Tutorial

HTML Background

Using an HTML background, we can change the background of any webpage. By default, our background webpage is white in color. It can be controlled using two ways:-

  • Using Color for Background in HTML
  • Using Image as Background in HTML

1. Background Using Colors

The bgcolor attribute was used in earlier versions of HTML to set the background color of a webpage. However, in HTML5, this attribute is deprecated and should not be used. Instead, the recommended way to set the background color of a webpage is by using CSS. This can be done by targeting the body element in CSS and setting its background-color property to the desired color.

Warning-Note Don’t use "bgcolor" attribute in HTML5. 

Output:

These bgcolor attributes value can be given in any form like color name, hex or rgb. It will show the same result.

2. Background Using Images

the background property can be used to set a background image in HTML and CSS. The image can have any format like jpg, gif or png. Or the value of the background property can be set to a URL pointing to the image file. 

Warning-Note In HTML5, this attribute is deprecated. Don’t use this attribute.

Output:

Go back to Previous Course