HTML TAGS
HTML tags are the basic building block of webpages. Tags are like a sign board which tells the browser how to display and format content inside the tag.
HTML tag starts and close with angle brackets (<tagname>) and the name of tag lies within the brackets. Example <p>
, <h1>
, <div>
, etc.
HTML tags are used in nested form. Like: <head>
and <body>
tags are used inside <html>
tag, inside <head>
we use <title>
tag and inside <body>
we use other tags like headings, paragraphs, etc.
The following example is a valid HTML code, you can see how HTML tags are nested in each other. Tags used in example below are <html>
, <head>
, <title>
, <body>
, <p>
and <h2>
.
Example
Note: HTML tags are always written in lowercase.
Lets discuss basic HTML tags here:-

html tag
<html>
tag is called root tag of HTML document because it is root element in tree of elements of a web page.- All other elements like head or body goes inside it.
- It contain all other element of web page except
<!DOCTYPE>
.
head tag
<head>
contain all necessary information related to web page but not actual content.- Information like: title, base address, script, meta data, style all resides in
<head>
. - Contents of
<head>
element is not diaplayed in web page.
Example
body tag
- A
<body>
tag defines body of HTML document. - All the element which are displayed on web page lies inside
<body>
tag. - Paragraphs, headings, images, videos,links every visible content is defined inside
<body>
tag.
Example
Heading tags
- Heading tags are used to give headings in HTML documents.
- There are six levels of headings representing six different sizes of heading.
- Headings are <h1>,<h2>,<h3>,<h4>,<h5> and <h6>. Where <h1> is biggest in size and <h6> is smallest in size.
Example
Paragraph tag
<p>
tag defines paragraphs in HTML documents. It is used to write content on webpage in form of a paragraph.- Writing content to one
<p>
tag and then moving to the next<p>
tag automatically changes the paragraph in the web page.
Example
Preformatted tag( pre tag)
<pre>
tag allows you to define spacing and lining itself in an HTML document.- Content on a web page is decorated in the same fashion as you define in
<pre>
tag.
Example
table tag
<table>
tag is used to create tables on a webpage. table tag contains many helper tags which are used within table tag to create table-rows, table-columns, table-cells, etc.- Some of helper table tags are
<tr>
,<th>
,<td>
, etc.
Example
list tags
<list>
tag is used to create lists on a webpage. list tag are of 2 types unordered and ordered list.- Unordered list is created using
<ul>
tag, whereas ordered list is created using<ol>
tag.
Example
br tag (line breaking tag)
In HTML line breaking is specified by the <br>
tag.
The <br>
tag is an empty tag. We do not need to close it in HTML but in XHTML it is not valid you have to close it as <br />
.
Example
<br>
in HTML but in XHTML it's not
valid instead we use <br />
hr tag
In HTML horizontal line is specified by the <hr>
tag.
The <hr>
tag is an empty tag.We need not to close it in HTML but in XHTML it is not valid you have to close it as <hr />
Example
<hr>
in HTML but in XHTML it's not
valid instead we use <hr />
.center tag
HTML <center>
tag is used to put any content in the center of the block of webpage.
Example
- HTML tags are building blocks of webpage. HTML tags can be written in nested form.
- There are 2 different types of HTML tags closing tags like p tag, heading tag, div tag and self closing tag like br tag, hr tag, img tag, etc.
- html tags contains all tags nexted inside it.