Browse Courses

Ultimate Guide to HTML Elements

Comprehensive guide to HTML elements with examples, best practices, and advanced tips.


HTML elements are the foundation of web development. This guide provides a comprehensive overview of HTML elements, categorized for easy reference, with examples, best practices, and advanced tips.


Introduction to HTML Elements

HTML elements define the structure and content of a web page. They are represented by tags and can include attributes to provide additional information.


Text Content

Headings

Headings are used to define titles and subtitles in an HTML document. Use <h1> for the main title and <h2> to <h6> for subheadings.

1<body>
2  <h1>Main Title</h1>
3  <h2>Subheading</h2>
4  <h3>Sub-subheading</h3>
5</body>

Adding Text in Paragraphs

The <p> tag defines a paragraph. Use it to group sentences into blocks of text.

1<body>
2  <h1>Main Title</h1>
3  <p>This is a paragraph. It contains multiple sentences.</p>
4  <p>This is another paragraph.</p>
5</body>

Adding Forced Line Breaks

A line break is used to complete one line and continue the remaining text at the start of a new line, like what was just done here. This can be useful in many scenarios, such as when writing addresses. You can use the
tag to insert a line break in HTML. This is not a container tag and does not have any end tag. It is a self-closing tag.

1<body>
2  <h1>Main Title</h1>
3  <p>
4    This is a paragraph. It contains multiple sentences.<br />
5    This is another paragraph.
6  </p>
7</body>

Blockquotes

The <blockquote> tag is used for quoting text.

1<blockquote cite="https://example.com">
2  This is a blockquote. It is used to quote text from another source.
3</blockquote>

  • The <a> tag defines a hyperlink.

Web pages can link to other pages or other places on the same page via a hyperlink. The tag defines a hyperlink in HTML, followed by the href attribute to define the destination address of the hyperlink.

Hyperlinks are normally inserted into text so that when you click some hyperlinked text, it takes you to the destination. For example, if you want to hyperlink the word “IBM” to the official IBM website, you can use the tag with the href attribute as shown below:

In the example above, anytime a user clicks the “IBM” text, the IBM website will open in the current tab. If you want a hyperlink to open a certain destination in a new tab, you can do so by adding target="_blank" to the tag as follows:


Images

The <img> tag defines an image. Always include the alt attribute for accessibility.

Audio and Video

Audio

Video


Lists

Unordered Lists

Ordered Lists

Definition Lists


Tables

Tables are used to display data in rows and columns.


Forms

Basic Form Structure

Form Elements


Semantic Elements

Semantic elements provide meaning to the structure of a web page. Examples include <header>, <footer>, <article>, and <section>.


Containers

Div

The <div> tag is a block-level container.

Span

The <span> tag is an inline container.


The <nav> tag defines navigation links.


The <footer> tag defines the footer of a document.


HTML File Setup

Browser Tab Title

Page Heading

Best Practices

  1. Use semantic HTML elements whenever possible.
  2. Ensure proper nesting of elements.
  3. Use meaningful text for links and buttons.
  4. Add alt text to images for accessibility.
  5. Validate forms to ensure user input meets requirements.

Advanced Tips

  1. Use ARIA roles for better accessibility.
  2. Optimize images for faster loading.
  3. Use <picture> for responsive images.
  4. Minimize inline styles; use CSS for styling.
  5. Test your HTML with validators to ensure compliance with standards.

Interactive Examples

Here are some live examples of HTML elements in action:

Basic HTML Elements

Form Elements

Example 3: Table Structure

✅ Table Structure (<table>) ✅ Table Rows (<tr>) ✅ Table Headers (<th>) ✅ Table Cells (<td>) ✅ Table Headers (<thead>) ✅ Table Body (<tbody>) ✅ Table Footer (<tfoot>) ✅ Column Spanning (colspan) ✅ Row Spanning (rowspan) ✅ Alternating Row Colors (nth-child) ✅ Table Caption (<caption>)


FAQ