HTML (HyperText Markup Language) is the fundamental language of the web, allowing developers to structure and present content on websites. As the backbone of every webpage, HTML defines elements such as headings, paragraphs, links, images, and multimedia, organizing them into a cohesive and accessible structure.
At the core of HTML are tags, the building blocks of web pages. Each tag serves a unique purpose, from defining the document’s main structure to styling and embedding media. Understanding these tags is essential for web development, enabling developers to create functional, accessible, and visually engaging websites.
This article aims to provide a comprehensive guide to HTML tags, complete with descriptions and examples, to serve as a practical resource for beginners and seasoned developers alike. By the end, readers will have a clear understanding of the most commonly used HTML tags and their applications in real-world scenarios.
List of Tags for HTML
1. <html> tag
This tag is the root element of an HTML document, serving as the container for all the content on a webpage. It wraps everything that will be displayed on the page, as well as metadata about the document. All other tags, like <head> and <body>, must be nested inside the <html> tag.
<html>
<!-- Page content -->
</html>
This tag ensures that the browser interprets the content as an HTML document.
-
<head> Tag
This tag contains metadata about the HTML document, which is not displayed directly on the webpage. This section defines the document’s title, link stylesheets, scripts, and other information essential for browsers and search engines.
<head>
<title>Page Title</title>
</head>
In this example, the <title> tag sets the text shown on the browser tab. Other common elements inside <head> include <meta>, <link>, and <script>.
-
<title> Tag
The <title> tag defines the title of the HTML document, which is displayed on the browser tab and used as the default title when the page is bookmarked. It is important for user experience and SEO as it helps identify the page’s content.
Example:
<title>Welcome to My Website</title>
In this example, “Welcome to My Website” will appear on the browser tab when the page is loaded.
-
<body> Tag
The <body> tag contains all the visible content of a webpage, such as text, images, videos, and other elements displayed in the browser.
Everything inside the <body> tag is rendered for users to see and interact with.
Example:
<body>
<h1>Hello World!</h1>
</body>
In this example, the browser will display the heading “Hello World!” as part of the webpage. All content meant to be viewed by users should be placed within the <body> tag.
5. <h1> to <h6> tags
The <h1> to <h6> tags are used to define headings in an HTML document, with <h1> being the largest and most important heading.
<h6> is the smallest and least significant. These tags help structure content hierarchically and improve readability and accessibility
<h1>Main Heading</h1>
<h2>Subheading</h2>
<h3>Sub-subheading</h3>
In this example:
- <h1> is used for the main title or top-level heading.
- <h2> is for a secondary heading subordinate to <h1>.
- <h3> is for further subdivisions, and so on till<h6>.
6. <p> Tag
The <p> tag is used to define a paragraph of text in an HTML document. It separates blocks of text to enhance readability and structure on a webpage. Browsers automatically add some space before and after each <p> tag for better visual presentation.
Example:
<p>This is a paragraph.</p>
In this example, the browser will display the text “This is a paragraph.” formatted as a distinct paragraph.
7. <a> Tag
The <a> tag is used to create hyperlinks, enabling users to navigate to other web pages, download resources, or access different sections of the same page. The href attribute specifies the link’s destination.
Example:
<a href="https://example.com">Visit Example</a>
In this example:
- “Visit Example” is the clickable text (anchor text).
- Clicking it directs the user to https://example.com.
Hyperlinks are essential for connecting content across the web and improving navigation and user experience.
8. <img> Tag
The <img> Tag is used to embed images in a webpage. It requires the src attribute to specify the image’s location and the alt attribute to describe the image for accessibility and SEO purposes.
Example:
<img src="image.jpg" alt="Description of Image">
In this example:
- src=”image.jpg” specifies the image file to be displayed.
- alt=”Description of Image” provides an alternative text that describes the image, which is displayed if the image cannot be loaded and is essential for screen readers.
The <img> tag is self-closing, meaning it doesn’t require a closing tag.
9. <ul> and <li> Tag
The <ul> tag is used to create an unordered (bulleted) list, and the <li> tag defines individual items within that list. This structure helps organize content in a clear, itemized format.
Example:
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
In this example:
- <ul> creates the unordered list.
- <li> defines each item within the list.
This setup results in a bulleted list with “Item 1” and “Item 2” as the list entries.
10. <ol> and <li> Tags
The <ol> tag is used to create an ordered (numbered) list, and the <li> tag defines individual items within that list. The items in an <ol> are automatically numbered by the browser.
Example:
<ol>
<li>Step 1</li>
<li>Step 2</li>
</ol>
In this example:
- <ol> creates the ordered list, displaying items in a numbered sequence.
- <li> defines each step or item within the list.
This will display as:
- Step 1
- Step 2
Ordered lists are useful for instructions or steps that need to be followed in a specific sequence.
11. <div> Tags
The <div> tag is a container element used to group content together, often for styling or layout purposes. It does not have any inherent visual styling but is commonly used with CSS to apply styles or organize elements within a webpage.
Example:
<div class="container">
<p>Content inside a div.</p>
</div>
In this example:
- <div class=”container”> creates a container around the paragraph.
- The class=”container” attribute can be used to apply CSS styles to the <div>.
The <div> tag is essential for structuring and styling content in modern web design.
12. <span>
The <span> tag is used to style inline elements or text without disrupting the flow of the content.
It’s often combined with CSS to apply specific styles to a portion of text or other inline elements within a block-level element like a paragraph.
Example:
<p>This is <span style="color: red;">red text</span>.</p>
In this example:
- <span> is used to apply a red color to a specific part of the text (“red text”) within the paragraph.
- The style=”color: red;” inline CSS changes the text color to red.
The <span> tag does not introduce any line breaks, making it ideal for styling small portions of content within larger blocks of text.
13. <form> tag
The <form> tag is used to enclose form elements, allowing users to input data that can be submitted to a server for processing. It typically includes form controls like text fields, checkboxes, and buttons, and it requires attributes like action (to specify where to send the data) and method (to define how to send it, such as GET or POST).
Example:
<form action="/submit" method="POST">
<input type="text" name="name">
</form>
In this example:
- The <form> tag wraps the input field for submitting data.
- The action=”/submit” attribute specifies that the form data should be sent to the /submit endpoint.
- The method=”POST” attribute indicates that the form data will be sent via the POST method, which keeps the data hidden from the URL.
The <form> tag is essential for gathering and submitting user input in web applications.
14. <button> Tag
This tag is used to create clickable buttons on a webpage. These buttons can trigger actions, such as submitting forms, running scripts, or navigating to other pages.
Example:
<button>Click Me</button>
In this example, the button displays the text “Click Me” and can be used by users to interact with it. You can also add event handlers (e.g., JavaScript) to define the button’s behavior when clicked.
15. <table> Tag
The <table> tag is used to display tabular data in rows and columns. It works with other tags like <tr> for table rows, <th> for table headers, and <td> for table data cells. This structure is crucial for organizing data in a readable format.
Example:
<table>
<tr>
<th>Header</th>
<th>Value</th>
</tr>
<tr>
<td>Item 1</td>
<td>100</td>
</tr>
</table>
In this example:
- <table> defines the table structure.
- <tr> creates a row in the table.
- <th> creates header cells, usually bold and centered.
- <td> defines the data cells.
This setup presents data in a tabular format, making it easy to compare values across different rows.