Loading...
HTML Background

HTML Background

In this tutorial, we will learn about background color and background images in HTML with the help of examples.


Background

By default, the webpage background color is white.

Html provides two attributes for the background :

  • Bg-color
  • Background

bgcolor Attribute

  • The bgcolor attribute is designed to control the background of the HTML page body and table background.
  • The bgcolor attribute is not used in HTML 5.0 and later versions.

Syntax

bgcolor = "color_value">

The color value can be used in 3 different ways:

  • Color Name - blue, green, white, yellow etc
  • Hex Value - #f2f5a1, #45ab12, #a1b2c3 etc
  • RGB Value - rgb(0,0,120), rgb(150,0,80), rgb(80,90,100) etc

Example :

<!DOCTYPE html>
<html>
  <head>
    <title>Image tag attr</title>
  </head>
  <body>
    <h3 bgcolor = "#f3a1ba">This is colored background 1.</h3>
    <h3 bgcolor = "#abd1c5">This is colored background 2.</h3>
  </body>
</html>

Output

This is colored background 1.

This is colored background 2.


background Attribute

  • The background attribute is used to control the background of an HTML element.
  • We can also specify an image to set background in HTML page.

Syntax

<tag_name background = "image URL">

Example :

<!DOCTYPE html>
<html>
  <head>
    <title>Image tag attr</title>
  </head>
  <body>
    <h3 background = "./html.png">This is background with image</h3>
  </body>
</html>

Output

This is background with image


Next Tutorial

We hope that this tutorial helped you develop better understanding of the concept of Background in HTML.

Keep Learning : )

In the next tutorial, you'll learn about HTML Colors.

- Related Topics