Tags and Attributes in HTML

HTML is built using tags and attributes to structure content and add functionality to web pages. Understanding these components is essential for creating robust and meaningful HTML documents.


What Are Tags?

Tags are the building blocks of HTML. They define the structure and content of a web page. Most tags have an opening and closing pair, while some are self-closing.

Types of Tags

  1. Paired Tags: Contain opening and closing tags.
    • Example: <p>This is a paragraph.</p>
  2. Void Tags: Self-closing and do not require an end tag.
    • Example: <img src="image.jpg" alt="Sample image" />

What Are Attributes?

Attributes provide additional information about an element. They are always specified in the opening tag and follow this structure:

<tagname attribute="value">Content</tagname>

Common Attributes


Comprehensive List of HTML Tags

Here’s a categorized list of common HTML tags:

Basic Document Structure Tags


Text Content Tags


Lists


Links and Navigation


Images and Multimedia


Tables


Forms


Semantic Tags


Scripting and Metadata


Others


Example with Tags and Attributes

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML Tags and Attributes</title>
</head>
<body>
    <header>
        <h1>Welcome to My Website</h1>
        <nav>
            <a href="#about">About</a> | <a href="#contact">Contact</a>
        </nav>
    </header>
    <main>
        <section id="about">
            <h2>About Me</h2>
            <p>Hello! I'm learning HTML.</p>
        </section>
        <section id="contact">
            <h2>Contact</h2>
            <form>
                <label for="name">Name:</label>
                <input type="text" id="name" name="name">
                <button type="submit">Submit</button>
            </form>
        </section>
    </main>
    <footer>
        <p>&copy; 2024 My Website</p>
    </footer>
</body>
</html>

By mastering tags and attributes, you can create structured, accessible, and visually appealing web pages. This foundational knowledge will also make it easier to learn advanced web technologies like CSS and JavaScript!