Skip to main content

What is a tag in HTML?

A tag in HTML is a building block of a web page, used to tell the browser exactly what to display and what role that element plays.

In simpler terms:

A tag is a command for the browser that describes the structure and meaning of the content.


What a tag looks like

A tag is a word enclosed in angle brackets < >. Most tags have an opening and a closing form:

html
<p>This is a paragraph of text.</p>
  • <p> is the opening tag (start of the element).
  • </p> is the closing tag (end of the element).
  • Everything between them is the content.

An example with several tags:

html
<h1>Page heading</h1> <p>Text below the heading.</p> <a href="https://example.com">Link</a> <img src="photo.jpg" alt="Photo">

Here:

  • <h1> is a heading,
  • <p> is a paragraph,
  • <a> is a link,
  • <img> is an image.

Types of tags

  1. Paired tags have an opening and a closing tag:
html
<div>Content</div> <p>Text</p>
  1. Single (self-closing) tags do not contain text inside and do not require closing:
html
<img src="photo.jpg" alt="Photo"> <br> <hr>

Tag attributes

Tags can have attributes: additional parameters that refine their behavior. They are written inside the opening tag.

Example:

html
<a href="https://example.com" target="_blank">Go</a>

Here:

  • href is the link address,
  • target="_blank" opens it in a new tab.

How the browser understands tags

The browser does not display the tags themselves, only interprets them:

  • <h1> makes the text a large heading,
  • <p> adds spacing between paragraphs,
  • <img> inserts a picture, and so on.

Summary:

TermMeaning
TagA command for the browser indicating which element to create
Opening tagThe start of an element (<p>)
Closing tagThe end of an element (</p>)
AttributeAn additional property of a tag (src, href, alt)
ElementEverything together: tag + content + attributes

In simple terms: A tag is a "label" that HTML uses to mark every piece of the page: where the heading is, where the text is, where the image is, and what to do with it. Without tags, the browser would not understand how to assemble a page from plain text.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.