A Comprehensive Guide to HTML Tags: Demonstrated in a Table
HTML (HyperText Markup Language) is the foundation of web development, and understanding its various tags is essential for building well-structured webpages. In this blog, we’ll provide a detailed overview of the most commonly used HTML tags, organized in a table format for easy reference.
This guide will give you an understanding of each tag’s purpose, along with a brief description of how and when to use them. Let’s get started!
HTML Tags Reference Table
Tag | Description | Example |
---|---|---|
`<html>` | Defines the root of an HTML document. | `<html lang="en"> ... </html>` |
`<head>` | Contains metadata for the HTML document such as title, character set, etc. | `<head><meta charset="UTF-8"><title>Page Title</title></head>` |
`<body>` | Contains the content of the webpage. | `<body> <h1>Welcome to My Website</h1> </body>` |
`<h1> - <h6>` | Defines HTML headings, from the most important (`<h1>`) to least important (`<h6>`). | `<h1>Main Heading</h1>` `<h2>Subheading</h2>` |
`<p>` | Defines a paragraph of text. | `<p>This is a paragraph of text.</p>` |
`<a>` | Creates a hyperlink to another web page or URL. | `<a href="https://www.example.com">Visit Example</a>` |
`<img>` | Embeds an image in the webpage. | `<img src="image.jpg" alt="Example Image">` |
`<ul>` | Defines an unordered (bulleted) list. | `<ul><li>Item 1</li><li>Item 2</li></ul>` |
`<ol>` | Defines an ordered (numbered) list. | `<ol><li>First Item</li><li>Second Item</li></ol>` |
`<li>` | Defines a list item, used within `<ul>` or `<ol>`. | `<li>List item content</li>` |
`<div>` | Defines a block-level container, often used for layout purposes. | `<div class="container"> ... </div>` |
`<span>` | Defines an inline container, often used for styling parts of content. | `<span class="highlight">Important Text</span>` |
`<br>` | Inserts a line break in the text. | `This is the first line.<br>This is the second line.` |
`<hr>` | Creates a horizontal rule or divider. | `<hr>` |
`<table>` | Defines a table. | `<table> ... </table>` |
`<tr>` | Defines a table row, used inside `<table>`. | `<tr><td>Row 1, Column 1</td><td>Row 1, Column 2</td></tr>` |
`<td>` | Defines a table data cell, used inside `<tr>`. | `<td>Table cell content</td>` |
Explanation of the HTML Tags
1. `<html>`
The `<html>` tag defines the root element of an HTML document. Everything on the webpage is enclosed within the `<html>` tags.
2. `<head>`
The `<head>` tag contains metadata, such as links to stylesheets, scripts, or the title of the page. It does not display content directly on the webpage.
3. `<body>`
All content that you want to display on the webpage is placed within the `<body>` tag. This includes text, images, links, etc.
4. `<h1>` to `<h6>`
These tags are used for creating headings, with `<h1>` being the most important (typically the title of the page) and `<h6>` being the least important.
5. `<p>`
The `<p>` tag is used for paragraphs. It automatically adds space before and after the text.
6. `<a>`
The `<a>` tag is used to create hyperlinks, enabling navigation from one page to another or to an external URL.
7. `<img>`
The `<img>` tag is used to embed images into a webpage. The `src` attribute defines the path to the image file, and the `alt` attribute provides alternative text.
8. `<ul>` and `<ol>`
The `<ul>` tag defines an unordered list (bulleted), while `<ol>` defines an ordered list (numbered). Both use `<li>` to define individual list items.
9. `<div>` and `<span>`
The `<div>` tag is a block-level container, often used for layout purposes, whereas `<span>` is an inline container used for styling small portions of text.
10. `<form>` and Related Input Tags
Forms are created using the `<form>` tag. Related tags such as `<input>`, `<textarea>`, and `<select>` are used to gather user input for interactive elements.
11. `<table>`, `<tr>`, `<td>`, and `<th>`
These tags are used to create tables. `<tr>` defines a row, `<td>` defines a data cell, and `<th>` defines a header cell in the table.
Conclusion
Understanding HTML tags is essential for anyone learning web development. The tags covered in this guide are foundational and will help you structure your web pages effectively. By mastering these tags and knowing how to use them in different scenarios, you’ll be well on your way to creating well-structured, accessible, and dynamic websites.
Happy coding!