Knowee
Questions
Features
Study Tools

Examples of HTML Class Attribute

Question

Examples of HTML Class Attribute

🧐 Not the exact question you are looking for?Go ask a question

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:

  1. 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".

  1. 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".

  1. 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".

This problem has been solved

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."

1/3

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.