top of page

Learn through our Blogs, Get Expert Help, Mentorship & Freelance Support!

Welcome to Colabcodes, where innovation drives technology forward. Explore the latest trends, practical programming tutorials, and in-depth insights across software development, AI, ML, NLP and more. Connect with our experienced freelancers and mentors for personalised guidance and support tailored to your needs.

blog cover_edited.jpg

A Beginner's Guide to the Most Common HTML Tags with Examples

Writer's picture: samuel blacksamuel black

Updated: 3 days ago

HTML (HyperText Markup Language) is the foundation of web development. It provides the structure for web pages using a collection of elements, commonly called "tags." Each tag serves a specific purpose, from defining headings and paragraphs to embedding images and links. In this blog, we’ll explore some of the most common HTML tags with practical examples.

HTML tags - colabcodes

What are HTML tags?

HTML tags are the fundamental elements used to structure and define the content of a web page. They are written within angle brackets, such as <tagname>, and typically come in pairs: an opening tag (e.g., <p>) and a closing tag (e.g., </p>). Tags tell the web browser how to interpret and display the enclosed content, such as text, images, links, or interactive elements. For instance, <h1> defines a main heading, <a> creates a hyperlink, and <img> embeds an image. While most tags enclose content, some, like <br> for line breaks or <img> for images, are self-closing. Understanding HTML tags is essential for building the structure and layout of any website.


Basic Structure of an HTML Document

The basic structure of an HTML document provides the foundation for creating any web page. It begins with the <!DOCTYPE html> declaration, which specifies the version of HTML being used. The document is enclosed within <html> tags, representing the root element. Inside, there are two main sections: the <head> and the <body>. The <head> contains metadata about the document, such as its title, character encoding, and links to external resources like stylesheets or scripts. The <body> holds the visible content displayed on the web page, including text, images, links, and other elements. This structured layout ensures browsers can interpret and render the web page correctly.

Before diving into specific tags, every HTML document follows this basic structure:

<!DOCTYPE html>
<html>
  <head>
    <title>Page Title</title>
  </head>
  <body>
    <h1>Welcome to My Web Page</h1>
    <p>This is a sample web page.</p>
  </body>
</html>

Key Tags in the Structure


  • <!DOCTYPE html>: Declares the document type.

  • <html>: The root element of an HTML document.

  • <head>: Contains metadata like the title, character set, and linked stylesheets.

  • <body>: Contains the visible content of the webpage.


Heading Tags (<h1> to <h6>)

Headings are used to structure content hierarchically. There are six levels, with <h1> being the largest and most important, and <h6> the smallest.


Example

<h1>Main Heading</h1>
<h2>Subheading</h2>
<h3>Sub-subheading</h3>

Paragraph Tag (<p>)

Defines a block of text or a paragraph.


Example

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

Anchor Tag (<a>)

Creates hyperlinks that navigate to other pages or external resources.


Example

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

Image Tag (<img>)

Displays images. It is a self-closing tag, meaning it doesn’t require a closing tag.


Attributes

  • src: Specifies the image URL.

  • alt: Provides alternative text if the image doesn’t load.


Example

<img src="example.jpg" alt="Sample Image" width="300" height="200">

Unordered List (<ul>)

Displays bullet-pointed lists.

<ul>
  <li>HTML</li>
  <li>CSS</li>
  <li>JavaScript</li>
</ul>

Ordered List (<ol>)

Displays numbered lists.

<ol>
  <li>Step 1</li>
  <li>Step 2</li>
  <li>Step 3</li>
</ol>

Table Tags (<table>, <tr>, <th>, <td>)

Used for displaying tabular data.


Example

<table border="1">
  <tr>
    <th>Name</th>
    <th>Age</th>
  </tr>
  <tr>
    <td>John</td>
    <td>25</td>
  </tr>
  <tr>
    <td>Jane</td>
    <td>30</td>
  </tr>
</table>

Div and Span Tags

Div (<div>)

A block-level container used to group content.

<div>
  <h2>Section Title</h2>
  <p>This is some grouped content.</p>
</div>

Span (<span>)

An inline container used for styling or grouping small content pieces.

<p>This is <span style="color:blue;">blue text</span>.</p>

Form Tags (<form>, <input>, <button>)

Form Structure

Used to collect user input.

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

Semantic tags provide meaning to the content.


  • <header>: Defines the header of a document or section.

  • <nav>: Represents navigation links.

  • <section>: Represents a section of the document.

  • <footer>: Defines the footer of a document.


<header>
  <h1>Website Header</h1>
</header>
<nav>
  <a href="#home">Home</a>
  <a href="#about">About</a>
</nav>
<section>
  <h2>About Us</h2>
  <p>This section contains information about us.</p>
</section>
<footer>
  <p>&copy; 2024 My Website</p>
</footer>

Conclusion

In conclusion, HTML is the backbone of web development, providing the structure and foundation for all web pages. Understanding the basic structure of an HTML document and its common tags is essential for anyone starting their web development journey. With practice, these tags enable developers to create well-organized, interactive, and visually appealing websites. By mastering HTML, you build a solid base for exploring advanced web technologies and frameworks, paving the way for professional and creative web development projects.

Comments


Get in touch for customized mentorship and freelance solutions tailored to your needs.

bottom of page