Skip to main content
  1. Web Development Course/
  2. Introduction to HTML/

Anatomy of an HTML tag

Alejandro AO
Author
Alejandro AO
I’m a software engineer building AI applications. I publish weekly video tutorials where I show you how to build real-world projects. Feel free to visit my YouTube channel or Discord and join the community.
Introduction to HTML - This article is part of a series.
Part 3: This Article

HTML tags are the building blocks of web pages, and understanding their anatomy is essential for creating well-structured and meaningful web content. Each HTML tag has a specific purpose and meaning, and consists of several different parts, including the opening tag, closing tag, and attributes. Here is a diagram that shows the anatomy of an HTML tag that I got from Wikipedia:

Anatomy of an HTML tag

Opening Tag
#

The opening tag is the first part of an HTML tag and is denoted by the “<” symbol, followed by the name of the tag, and closed with a “>”. For example, the opening tag for a paragraph is:

 <p>

This opening tag tells the web browser to start a new paragraph and to apply any associated styles or formatting.

Closing Tag
#

The closing tag is the second part of an HTML tag and is denoted by the “</” symbol, followed by the name of the tag, and closed with a “>”. For example, the closing tag for a paragraph is:

</p>

This closing tag tells the web browser to end the paragraph and to stop applying any associated styles or formatting.

Content
#

The content of an HTML tag is the information that is displayed on the web page. It is placed between the opening and closing tags and can be text, images, or other media. For example, the content of a paragraph tag might be:

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

In this example, “This is a paragraph of text.” is the content of the paragraph.

Attributes
#

HTML tags can also include attributes, which provide additional information about the tag. Attributes are placed inside the opening tag, and are denoted by the attribute name followed by an equals sign (=), and the attribute value enclosed in quotation marks.

Some attributes are required for certain HTML tags, while others are optional. For example, the “src” attribute is required for the image tag, while the “alt” attribute is optional.

<img src="example.jpg">

In this example, “example.jpg” is the value of the “src” attribute. This means that the image tag will display the image located at the URL “example.jpg”.

By understanding the anatomy of an HTML tag, you can create web content that is well-structured, meaningful, and visually appealing. Remember to always include the opening and closing tags for each HTML element, and to use attributes appropriately to provide additional information about your content. Now let’s take a closer look at the different types of HTML attributes.

Introduction to HTML - This article is part of a series.
Part 3: This Article