What is Attributes
- Every HTML tag has some attribute associated with it, attributes define the specification of that tag.
- For example: If you are a human being, then your attributes/specifications are height, weight, age, color, etc.
- An attribute is always written in the opening tag.
- An attribute is always written in name="value" pair.
- Attribute value always enclosed in double quotes or single quotes.
Body tag attributes
- We have already learned, How to create a basic HTML page.
- A basic HTML page contains at least head and body tags.
- Body tag has various attributes associated with it, we have discussed some of them here in this article.
- text: This attributes used to define the text color in the body means your HTML content written in the body tag.
- bgcolor: This attribute is used to define the background color of the body (Web page).
- 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.
- As shown in the above figure body tag is created with two attributes...
- bgcolor = "red": which makes the red background of the body.
- text = "white": which makes body text of color white.
- The output of the above example is shown in the figure below...
- As you have seen in the above example, we have used the color name like red and white for the color.
- But in computer science, there are other popular methods to provide the colors as listed below...
- Color by name
- HEX color codes
- RGB color codes
Color by name
In this method, we simply write the color names like red, green, white.
Color by HEX codes
- The most popular are the Hex color codes.
- It consists of six digits.
- It always starts with the #(hash) symbol.
- Each pair of characters in the Hex code, representing the intensity of red, green and blue in the color respectively.
- Example: #XXXXXX
- Hex code pair values range from 00, which is the lowest intensity of a color, to FF which represents the highest intensity.
RGB color codes
- In RGB color can be written as given below.
- Example: rgb(red, green, blue)
- Each parameter (red, green, and blue) defines the intensity of the color between 0 and 255.