Home » HTML » HTML Tags

HTML Tags

HTML Tags: The whole HTML functions on HTML Tags. These HTML tags are the basic building block of a website. Without these tags, there would be no website. No web technologies like CSS, PHP, Python, WordPress, etc. will exist without HTML Tags. These are the driving force of the internet. So, the question is, what is an HTML Tag? Let's find out!

What is HTML Tag?

HTML Tags are pre-defined elements in HTML, enclosed within these < > signs. For example: <html>, <table>, etc. All HTML tags have a particular work associated with them. Each one has a special function and a combination of various tags forms a website. For example, a <p> tag defines a paragraph in the website and a <table> tag displays a table.

All HTML Tags are predefined, i.e., you cannot make HTML tags by yourself. Look at the example below, this is an example of a paired tag. Observe that there are two tags of same name, but the latter one has a slash / before it, it is a closing tag. Now, what is a closing tag? Let's start with different types of tags!

Syntax:

<p> Content </p>

Types of HTML Tags

There are two types of HTML Tags which are used by the Website Developers:

  1. Paired Tags (Open and Close Tags)
  2. Unpaired Tags (Singular Tag)

Paired Tags

Paired tags are a set of two tags with the same name. In each Paired tag set, one is an opening tag, and the other one is the closing tag. The closing tag has a / slash, it means that the tag is closed now.

It is necessary to close a paired tag; otherwise, it can result in the malfunctioning of the website. When the content is written within paired tags, then it ensures that the effect of those tags would be limited to only the content between them.

Look at the list of some paired tags in HTML below. Notice that each tag has a closing tag with a slash(/) before the name of the tag.

Syntax: <tag> Content </tag>

Example: HTML Code Tag

<code>  text..  </code>

List of some paired tags in HTML:

Open Tag Close Tag
<html> </html>
<table> </table>
<form> </form>
<span> </span>
<ul> </ul>
<p> </p>
<head> </head>
<div> </div>

Unpaired Tags (Singular Tags)

Unpaired tags are single tags with no closing tag. These tags are also called Singular Tags. These are also called non-container tags because they do not contain any content.

It is recommended to close the unpaired/singular tags also. But unfortunately, we do not have the closing tag for those. So, an unpaired tag is closed after adding a slash(/) just before the greater than > sign. For example: <br />.

Look below the list of some Unpaired Tags in HTML. Notice the use of slash(/) in the tags, to close them.

Some Unpaired Tags are:

Open Tag
<br>
<hr>
<meta>
<input>

HTML Heading Tag

Heading tag is used to give headings of different sizes in a document. There are six different HTML heading tags, which gives different heading sizes and are defined by <h1> to <h6> tags. <h1> gives the largest heading and <h6> gives the smallest one. So <h1> can be used for most important headings and <h6> can be used for a least important one.


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> HTML Heading Tag </title>
</head>
<body>
<h1> This is Heading 1 </h1>
<h2> This is Heading 2 </h2>
<h3> This is Heading 3 </h3>
<h4> This is Heading 4 </h4>
<h5> This is Heading 5 </h5>
<h6> This is Heading 6 </h6>
</body>
</html>

Output

HTML Heading Example

This is Heading 1

This is Heading 2

This is Heading 3

This is Heading 4

This is Heading 5
This is Heading 6

HTML Paragraph Tag

The <p> tag is used to define a paragraph in a document. HTML paragraph or HTML <p> tag gives the text inside it, a paragraph like finishing. It is a notable point that a browser itself add an empty line before and after a paragraph.

Let's take a simple example to see how it works.


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> HTML Paragraph Tag </title>
</head>
<body>
<p> This is First Paragraph </p>
<p> This is Second Paragraph </p>
<p> This is Third Paragraph </p>
</body>
</html>

Output

HTML Paragraph Tag Example

This is First Paragraph

This is Second Paragraph

This is Third Paragraph


HTML Anchor Tag

HTML Hyperlink is defined with the <a> tag (Anchor tag). It is used to give a link to any file, webpage, image etc.

This tag is called anchor tag and anything between the opening <a> tag and the closing </a> tag becomes part of the link, and a user can click that part to reach to the linked document.

Following is the simple syntax to use <a> tag.


<!DOCTYPE html>
<HTML lang="en">
<head>
<meta charset="UTF-8">
<title> HTML Anchor Tag </title>
</head>
<body>
<a target="_blank" href="https://www.coderepublics.com"> This is a link </a>
</body>
</html>

Output

HTML Anchor Tag Example This is a link


Note : Use 'target = _blank' as an attribute in <a> tag to open the link in a new tab.


HTML Image Tag

The Image Tag is used to add Images in HTML documents. The HTML <img> tag is used to add image in a document. The 'src' attribute is used to give source(address) of the image. The height and width of the image can be controlled by the attributes - height="px" and width="px".

The 'alt' attribute is used as an alternative in a case if the image is not shown. Anything written as a value of this attribute will be displayed. It will give information about the image.


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> HTML Image Tag </title>
</head>
<body>
<img src="HTML-Image.png" width="400px" height="200px">
</body>
</html>

Output

HTML Image Tag Example
HTML Image

Hope this tutorial will help you to understand the basic fundamental of HTML tags. To lwaen more about HTML Element we suggest you to go WikiPedia page.