1.3 HTML Tags and Elements | HTML

1.3 HTML Tags and Elements
Table of Contents

In HTML, tags and elements are the building blocks of web pages. They are used to structure and format content, allowing web browsers to interpret and display the content correctly. 

Understanding the difference between tags and elements is crucial for anyone learning HTML.

What are HTML Tags?

HTML tags are the code snippets enclosed within angle brackets (< >). They define the beginning and end of HTML elements and give instructions to the web browser on how to display content. Tags usually come in pairs: an opening tag and a closing tag. Some tags are self-closing.

Opening tag: <tagname>

Closing tag: </tagname>

Self-closing tag: <tagname /> (in HTML5, self-closing tags are just written as <tagname>)

What are HTML Elements?

HTML elements are the complete sets of tags and the content they contain. An element typically consists of an opening tag, content, and a closing tag.

<tagname>Content goes here</tagname>

For example, a paragraph element:

<p>This is a paragraph.</p>

Common HTML Tags and Elements

Let's explore some of the most commonly used HTML tags and elements:

1. Headings

Headings are used to define titles or subtitles. HTML provides six levels of headings, from <h1> (highest level) to <h6> (lowest level).

<h1>This is an H1 heading</h1>
<h2>This is an H2 heading</h2>
<h3>This is an H3 heading</h3>

2. Paragraphs

Paragraphs are used to define blocks of text.

<p>This is a paragraph of text.</p>

3. Links

Links (or hyperlinks) allow users to navigate from one page to another. The <a> tag is used to create links.

<a href="https://www.example.com">Visit Example</a>

4. Images

Images are embedded in web pages using the <img> tag. This tag is self-closing.

<img src="image.jpg" alt="Description of image">

5. Lists

Lists can be ordered (numbered) or unordered (bulleted).

Ordered list:

<ol>
    <li>First item</li>
    <li>Second item</li>
    <li>Third item</li>
</ol>

Unordered list:

<ul>
    <li>First item</li>
    <li>Second item</li>
    <li>Third item</li>
</ul>

6. Tables

Tables are used to display data in a tabular format.

<table>
    <tr>
        <th>Header 1</th>
        <th>Header 2</th>
    </tr>
    <tr>
        <td>Data 1</td>
        <td>Data 2</td>
    </tr>
</table>

7. Forms

Forms are used to collect user input.

<form action="/submit-form" method="post">
    <label for="name">Name:</label>
    <input type="text" id="name" name="name">
    <input type="submit" value="Submit">
</form>

8. Attributes

HTML tags can have attributes that provide additional information about elements. Attributes are always included in the opening tag and come in name/value pairs, such as name="value".

<a href="https://www.example.com" target="_blank">Visit Example</a>
<img src="image.jpg" alt="Description of image">

9. Nesting HTML Elements

HTML elements can be nested inside other elements to create a structured and organized document. For example, you can nest a list inside a paragraph or a link inside a list item.

<p>This is a paragraph with a <a
  href="https://www.example.com">link</a>.</p>
<ul>
      <li>First item with a <a
  href="https://www.example.com">link</a></li>
    <li>Second item</li>
</ul>

10. Closing HTML Tags

Most HTML tags require a closing tag, but some are self-closing. It's important to properly close tags to ensure the HTML document is correctly interpreted by web browsers.

With closing tags:

<p>This is a paragraph.</p>

Self-closing tags:

<img src="image.jpg" alt="Description of image">

Summary

Understanding HTML tags and elements is essential for creating structured and well-formatted web pages. Here are the key points:

    • HTML tags are enclosed in angle brackets and usually come in pairs (opening and closing).

    • HTML elements consist of an opening tag, content, and a closing tag.

    • Common HTML tags include headings, paragraphs, links, images, lists, tables, and forms.

    • Attributes provide additional information about elements and are included in the opening tag.

    • Proper nesting and closing of HTML tags are important for creating well-formed documents.

By mastering HTML tags and elements, you'll be well on your way to creating functional and visually appealing web pages.

To learn more about HTML, click here: HTML

I post, u read. Read more.

Post a Comment

Don't spam links or promote stuff in the comments. It's annoying and lowers the conversation quality. Contribute respectfully and helpfully instead.