Skip to main content

What is an HTML tag?

Suggest an edit

An HTML tag is an element of the HTML language that tells the browser exactly what to display on a web page and what role that element plays.

A tag indicates where a certain type of content begins and ends: for example, a paragraph, a heading, an image, or a link.


The structure of a tag

Most tags consist of an opening and a closing element:

html
<p>This is a paragraph of text.</p>
  • <p> is the opening tag, marking the start of the paragraph.
  • </p> is the closing tag, marking the end.
  • Between them is the content of the element.

Single tags

Some tags do not require closing because they contain no text inside:

html
<img src="photo.jpg" alt="Photo"> <br> <hr>

Such tags are called self-closing: they perform an action (insert a picture, a line break, a line), but do not wrap content.


Tag attributes

Tags can have attributes that specify their behavior or appearance. Attributes are written inside the opening tag in the format name="value".

Example:

html
<a href="https://example.com" target="_blank">Go</a>
  • href is the link,
  • target="_blank" opens it in a new tab.

Examples of tags and their purposes

TagPurpose
<h1>-<h6>Headings of different levels
<p>A paragraph of text
<a>A link
<img>An image
<div>A container for blocks
<span>An inline container for text
<ul> / <li>Lists
<table>A table

Summary:

ConceptMeaning
TagA command for the browser describing the type of an element
Paired tagHas an opening and a closing form
Single tagDoes not require closing
AttributeAn additional property of a tag

In simple terms: HTML tags are the "labels" a page is made of. The browser reads them and understands: where the text is, where the image is, where the button is, and where the link is.

Short Answer

Interview ready
Premium

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

Suggest an edit