Examples of HTML Class Attribute
Question
Examples of HTML Class Attribute
Solution
The HTML class attribute is used to define equal styles for elements with the same class name. So, all HTML elements with the same class attribute will get the same style.
Here are some examples:
- Single Class Attribute:
<!DOCTYPE html>
<html>
<head>
<style>
.center {
text-align: center;
color: red;
}
</style>
</head>
<body>
<h1 class="center">Red and Centered Heading</h1>
<p class="center">Red and Centered Paragraph.</p>
</body>
</html>
In this example, the class attribute with the value "center" is used to center the text and change its color to red for the elements with the class "center".
- Multiple Class Attributes:
<!DOCTYPE html>
<html>
<head>
<style>
.center {
text-align: center;
}
.large {
font-size: 200%;
}
</style>
</head>
<body>
<h1 class="center large">Centered and Large Heading</h1>
</body>
</html>
In this example, the class attribute with the value "center large" is used to center the text and make its font size 200% for the elements with the class "center large".
- Class Attribute in CSS:
<!DOCTYPE html>
<html>
<head>
<style>
.blue {
color: blue;
}
</style>
</head>
<body>
<p class="blue">This is a blue paragraph.</p>
</body>
</html>
In this example, the class attribute with the value "blue" is used to change the text color to blue for the elements with the class "blue".
Similar Questions
What is use of class attribute in HTML?
All HTML elements can have attributes.
Which attribute is used to provide additional information about an HTML element?Optionsclassstyletitleid
Which attribute is used to provide a unique identifier for an HTML element?*classidentifierid
Describe three (3) attributes that can be utilized with an HTML table, providing examples for each attribute."
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.