HTML Class Attribute

The class attribute is used to assign a specific class name to an HTML element, allowing for grouping and styling multiple elements with the same CSS rules. This promotes cleaner code and easier maintenance.

Tutorials dojo strip

HTML Class Attribute Syntax

Explanation of Syntax:

  • tagname: The name of the HTML element (e.g., <div>, <p>).
  • class="class_name": The class attribute specifies the class name, which can be referenced in CSS for styling.
HTML




HTML Class Attribute Example Code

Explanation of Code:

  • The code begins with the <!DOCTYPE html> declaration and the opening <html> tag.
  • In the <head> section, a simple CSS style block defines a class named .highlight, giving elements a yellow background and bold text.
  • The <body> section contains:
    • An <h1> tag assigned the class “highlight,” causing it to have a yellow background and bold text.
    • A regular <p> tag without a class.
    • A second <p> tag also assigned the class “highlight,” applying the same styling as the heading.
HTML




HTML Labs

Tutorials dojo strip