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:
<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:
<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
- Paired tags have an opening and a closing tag:
<div>Content</div>
<p>Text</p>- Single (self-closing) tags do not contain text inside and do not require closing:
<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:
<a href="https://example.com" target="_blank">Go</a>Here:
hrefis 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:
| Term | Meaning |
|---|---|
| Tag | A command for the browser indicating which element to create |
| Opening tag | The start of an element (<p>) |
| Closing tag | The end of an element (</p>) |
| Attribute | An additional property of a tag (src, href, alt) |
| Element | Everything 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 readyA concise answer to help you respond confidently on this topic during an interview.