In HTML, We are writing the code in tags format and all the tags are predefine that why html is markup language.
Tag: Tag, The text which is surrounding by angular bracket is known as tags.
There are two type of tag:
- Paired tag
- Unpaired tag/ Self-Closing tag
Paired tag: In paired tag there is both tag, Opening tab and Closing tag is known as paired tags.
Syntax: <tag> </tag>
Example of paired tag:
<html> </html>
<body> </body>
<head> </head>
<div> </div>
<p> </p>
<a> </a>
… etc.
or
Paired tags:
Paired tags, or elements with both opening and closing tags, enclose content and define its boundaries. They consist of an opening tag, some content, and a closing tag.
Example:
<h1>Welcome to My Website</h1>
<p>This is a paragraph of text.</p>
<a href="https://example.com">Visit Example</a>
In these examples:
<h1>
is the opening tag for a heading element, and</h1>
is the closing tag. The content “Welcome to My Website” is enclosed between them.<p>
is the opening tag for a paragraph element, and</p>
is the closing tag. The content “This is a paragraph of text.” is enclosed between them.<a href="https://example.com">
is the opening tag for a hyperlink, and</a>
is the closing tag. The content “Visit Example” is the clickable text for the link.
Paired tags help organize and structure the content on a webpage.
Unpaired tag/ Self-Closing tag:
Unpaired tags, or self-closing tags, are HTML elements that don’t require a separate closing tag. They are used for elements that don’t have any content between an opening and closing tag.
Example:
<img src="image.jpg" alt="Description of image">
<br>
<hr>
In this example:
<img>
is used to embed an image. It has attributes likesrc
(source) andalt
(alternative text). It doesn’t require a closing tag.<br>
is used to insert a line break. It also doesn’t require a closing tag.<hr>
is used to create a horizontal rule or line. It too is self-closing.
In HTML5, the self-closing slash (/
) is optional, so you may often see these tags written without it, like <img src="image.jpg" alt="Description of image">
.
Note:- All the tag are predefine its means we can’t create, change and destroy the tag, Only we can use according to out requirement.