What parts make up an HTML tag?
An HTML tag consists of three main parts: the tag name, attributes, and content (if the tag is paired).
1. The tag name
This is a keyword enclosed in angle brackets < > that defines which element to create.
Examples:
<p> - a paragraph
<h1> - a heading
<a> - a link
<img> - an imageThe tag name tells the browser how to interpret the content: as text, a link, an image, and so on.
2. Attributes (optional)
Attributes specify the behavior or appearance of an element.
They are written inside the opening tag and consist of a pair:
name="value"
Example:
<a href="https://example.com" target="_blank">Link</a>Here:
hrefis the link address,target="_blank"opens it in a new tab.
Attributes give a tag "settings", like function parameters in programming.
3. Content
This is what is located between the opening and closing tag: text, other tags, or elements.
Example:
<p>This is the paragraph's content.</p><p>is the opening tag,</p>is the closing tag,This is the paragraph's content.is the content.
The structure of a paired tag:
<name attribute="value">content</name>Example:
<a href="https://example.com">Go</a>The structure of a single (self-closing) tag:
<name attribute="value">Example:
<img src="photo.jpg" alt="Photo">Single tags contain no text and do not require closing.
Summary:
| Part | Purpose |
|---|---|
| Tag name | Defines the type of the element |
| Attributes | Specify behavior or properties |
| Content | What is shown to the user (if the tag is paired) |
In simple terms: An HTML tag is like a container with a label (name), settings (attributes), and content. The browser reads these parts to understand exactly what to show and how it should work.
Short Answer
Interview readyA concise answer to help you respond confidently on this topic during an interview.