⬅ Previous Next ➡

5. HTML Tags & Attributes

HTML Tags & Attributes
  • HTML Tags vs. Elements:
    • Tag: The basic building block of HTML. It consists of a name surrounded by angle brackets (e.g., <p>).
    • Element: The complete component, consisting of the opening tag, the content, and the closing tag.
  • Paired and Unpaired Tags:
    • Paired Tags (Container Tags): These come in sets of two. They have an opening tag and a closing tag (indicated by a /).
      • Example: <h1>Heading</h1>, <b>Bold</b>.
    • Unpaired Tags (Empty or Self-Closing Tags): These do not have a closing tag because they do not contain text content. They just insert something into the page.
      • Example: <br> (line break), <hr> (horizontal rule), <img> (image).
  • HTML Attributes:
    • Attributes provide additional information about an element.
    • They are always specified in the opening tag.
    • They usually come in name/value pairs like: name="value".
  • Global Attributes (Can be used with almost any HTML tag):
    • id: A unique identifier for an element. No two elements in the same document can have the same id. Used for linking and styling specific items.
    • class: Used to group multiple elements together. Many elements can share the same class name. Very useful for CSS styling.
    • title: Provides extra info about an element (often shown as a "tooltip" when you hover your mouse over the element).
    • style: Used to add inline CSS directly to an element (e.g., changing color or size).
    • lang: Specifies the language of the element's content (e.g., lang="en").
<!-- Example of Tags and Attributes -->
<!-- Paired tag with ID and Title attributes -->
<h2 id="main-header" title="Introduction Section">Welcome</h2>

<!-- Unpaired tag with Class attribute -->
<hr class="blue-line">

<!-- Paired tag with Class attribute -->
<p class="description">This is a paragraph.</p>
⬅ Previous Next ➡