Skip to main content

Command Palette

Search for a command to run...

Understanding HTML Tags and Elements: A Complete Beginner's Guide

Published
8 min read
Understanding HTML Tags and Elements: A Complete Beginner's Guide

HTML is the foundation of every website you visit. When you open a browser and see text, images, buttons, and forms on a webpage, all of that structure comes from HTML. Think of HTML as the skeleton of a webpage. Just like your skeleton gives your body structure and shape, HTML gives a webpage its structure and organization.

What is HTML and Why Do We Use It

HTML stands for HyperText Markup Language. It is not a programming language but a markup language that tells the browser how to display content on a webpage. Without HTML, browsers would not know how to organize text, where to place images, or how to create links between pages.

We use HTML because it provides a standardized way to create web content. Every browser understands HTML, which means a webpage you create will look consistent across different devices and platforms. HTML allows us to define headings, paragraphs, lists, links, images, and much more. It is the first step in web development and works together with CSS for styling and JavaScript for interactivity.

What is an HTML Tag

An HTML tag is a piece of code that tells the browser what kind of content to display and how to structure it. Tags are written inside angle brackets. For example, the paragraph tag looks like this: <p>. Tags act as containers that wrap around content and give it meaning.

Think of tags like boxes or labels. When you pack items for moving, you put them in boxes and label each box so you know what is inside. Similarly, HTML tags wrap around content and label it so the browser knows what type of content it is dealing with.

Most HTML tags come in pairs: an opening tag and a closing tag. The opening tag marks where the content starts, and the closing tag marks where it ends. The closing tag looks exactly like the opening tag but has a forward slash before the tag name.

Opening Tag, Closing Tag, and Content

Let me show you how this works with a real example. Suppose you want to create a paragraph on your webpage. You would write:

html

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

In this example, <p> is the opening tag, This is a paragraph of text. is the content, and </p> is the closing tag. The opening tag tells the browser that a paragraph is starting, the content is what actually appears on the page, and the closing tag tells the browser that the paragraph has ended.

The same pattern applies to other tags. For a heading, you might write:

html

<h1>Welcome to My Website</h1>

Here, <h1> is the opening tag for a top level heading, Welcome to My Website is the content, and </h1> is the closing tag. The browser will display this as a large, bold heading because that is what the h1 tag represents.

What is an HTML Element

This is an important distinction that confuses many beginners. An HTML element is the complete package: the opening tag, the content, and the closing tag all together. When we talk about a paragraph element, we mean the entire thing from <p> to </p>, including everything inside.

So the tag is just the label in angle brackets, while the element is the whole structure. Think of it this way: if the tag is the box, the element is the box plus everything inside it. For example:

html

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

The tags are <p> and </p>. The element is the entire line including the content. This distinction matters when you start learning CSS and JavaScript because you will often select and style entire elements, not just tags.

Self-Closing or Void Elements

Not all HTML elements need both an opening and closing tag. Some elements are called self-closing or void elements because they do not contain any content between tags. These elements close themselves in a single tag.

A common example is the image tag:

html

<img src="photo.jpg" alt="A beautiful sunset">

Notice there is no closing </img> tag. The image tag just points to an image file and displays it. There is no content to wrap around, so it closes itself. Other examples of self-closing elements include the line break tag <br> and the horizontal rule tag <hr>.

You might sometimes see self-closing tags written with a slash before the closing bracket like <img /> or <br />. Both styles work in HTML5, but the slash is optional and many developers leave it out.

Block-Level vs Inline Elements

HTML elements behave differently in how they take up space on a webpage. Understanding the difference between block-level and inline elements will help you predict how your content will appear on the page.

Block-level elements always start on a new line and take up the full width available. They stack on top of each other like building blocks. Common block-level elements include paragraphs <p>, headings <h1> through <h6>, divs <div>, and lists <ul> and <ol>.

For example, if you write:

html

<h1>First Heading</h1>
<p>First paragraph.</p>
<p>Second paragraph.</p>

Each element will appear on its own line, one below the other, taking up the full width of its container.

Inline elements, on the other hand, do not start on a new line. They only take up as much width as necessary and can sit next to other inline elements on the same line. Common inline elements include links <a>, spans <span>, images <img>, and text formatting tags like <strong> and <em>.

For example:

html

<p>This is a <strong>bold word</strong> in a sentence.</p>

The strong element sits inline within the paragraph. It does not force a line break. It just makes that specific word bold while staying on the same line.

Commonly Used HTML Tags

Let me walk you through some of the most common HTML tags you will use when building webpages. These tags cover most of the basic content you need to structure a page.

Headings are used to create titles and subtitles. HTML provides six levels of headings from <h1> to <h6>. The h1 tag is the most important and largest, while h6 is the least important and smallest. Use h1 for your main page title and h2 through h6 for subheadings.

html

<h1>Main Title</h1>
<h2>Section Title</h2>
<h3>Subsection Title</h3>

The paragraph tag <p> is used for blocks of text. Most written content on a webpage goes inside paragraph tags.

html

<p>This is a paragraph with some text content.</p>

The div tag <div> is a generic container used to group other elements together. It is a block-level element with no special meaning, but it is incredibly useful for organizing your page and applying styles.

html

<div>
  <h2>Article Title</h2>
  <p>Article content goes here.</p>
</div>

The span tag <span> is similar to div but it is inline. It is used to group or style specific parts of text without affecting the layout.

html

<p>This is <span style="color: red;">red text</span> in a paragraph.</p>

Links are created with the anchor tag <a>. The href attribute tells the browser where the link should go.

html

<a href="https://example.com">Click here to visit Example</a>

Images are added with the img tag. The src attribute specifies the image file, and the alt attribute provides alternative text for accessibility.

html

<img src="logo.png" alt="Company Logo">

Lists come in two types. Unordered lists <ul> create bulleted lists, and ordered lists <ol> create numbered lists. Both use list item tags <li> for each item.

html

<ul>
  <li>First item</li>
  <li>Second item</li>
  <li>Third item</li>
</ul>

The line break tag <br> forces content to move to the next line without creating a new paragraph.

html

<p>First line<br>Second line</p>

The strong tag <strong> makes text bold and indicates importance, while the em tag <em> makes text italic and adds emphasis.

html

<p>This is <strong>important</strong> and this is <em>emphasized</em>.</p>

Learning by Doing: Inspect HTML in Your Browser

One of the best ways to learn HTML is to look at real websites and see how they are built. Every modern browser has developer tools that let you inspect the HTML of any webpage.

To inspect HTML in your browser, right-click on any element on a webpage and select "Inspect" or "Inspect Element" from the menu. This will open the developer tools and show you the HTML code for that part of the page. You can see the tags, elements, and how everything is structured.

Try this with different websites. Look at headings, paragraphs, images, and links. Notice how the HTML is organized and what tags are used for different types of content. This hands-on exploration will help you understand HTML much faster than just reading about it.

Putting It All Together

HTML is the skeleton of the web. It uses tags to define different types of content, and elements are the complete structures that include the tags and content. Some elements are block-level and stack vertically, while others are inline and flow with the text. Some elements need closing tags, while others are self-closing.

Start simple. Practice with basic tags like paragraphs, headings, divs, and spans. Create small HTML files and open them in your browser to see how they look. Use the browser's inspect tool to learn from existing websites. As you get comfortable with these fundamentals, you will be ready to move on to more advanced HTML features and start styling your pages with CSS.

Remember, every expert web developer started exactly where you are now, learning what tags and elements are and how they work. Take your time, experiment with the code, and don't be afraid to make mistakes. That is how you learn.

HTML Tags and Elements: Beginner's Guide