HTML Attributes

What is Attributes

  1. Every HTML tag has some attribute associated with it, attributes define the specification of that tag.
  2. For example: If you are a human being, then your attributes/specifications are height, weight, age, color, etc.
  3. An attribute is always written in the opening tag.
  4. An attribute is always written in name="value" pair.
  5. Attribute value always enclosed in double quotes or single quotes.

Body tag attributes

  1. We have already learned, How to create a basic HTML page.
  2. A basic HTML page contains at least head and body tags.
  3. Body tag has various attributes associated with it, we have discussed some of them here in this article.
    1. text: This attributes used to define the text color in the body means your HTML content written in the body tag.
    2. bgcolor: This attribute is used to define the background color of the body (Web page).
    3. background: This attribute is used to add any background images of your web page.


Let's see an HTML page example to demonstrate how attributes work.


  1. As shown in the above figure body tag is created with two attributes...
    1. bgcolor = "red": which makes the red background of the body.
    2. text = "white": which makes body text of color white.
  2. The output of the above example is shown in the figure below...

Color codes

  1. As you have seen in the above example, we have used the color name like red and white for the color.
  2. But in computer science, there are other popular methods to provide the colors as listed below...
    1. Color by name
    2. HEX color codes
    3. RGB color codes

Color by name

In this method, we simply write the color names like red, green, white.

Color by HEX codes

  1. The most popular are the Hex color codes.
  2. It consists of six digits.
  3. It always starts with the #(hash) symbol.
  4. Each pair of characters in the Hex code, representing the intensity of red, green and blue in the color respectively.
  5. Example: #XXXXXX
  6. Hex code pair values range from 00, which is the lowest intensity of a color, to FF which represents the highest intensity.

ColorHex Code
Black #000000
White #ffffff
Red #ff0000
Green #00ff00
Blue #0000ff

RGB color codes

  1. In RGB color can be written as given below.
    1. Example:  rgb(red, green, blue)
  2. Each parameter (red, green, and blue) defines the intensity of the color between 0 and 255.

Attributes in HTML video tutorial