tutorialstonight logo
A Platform To Learn To Code

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

Run the code

Note: HTML tags are always written in lowercase.


Lets discuss basic HTML tags here:-

html tags

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

Run the code

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

Run the code

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

Run the code

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

Run the code

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

Run the code

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

Run the code

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

Run the code
NOTE:It is valid to use <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

Run the code

NOTE:It is valid to use <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

Run the code
points to remember Points to remember:
  1. HTML tags are building blocks of webpage. HTML tags can be written in nested form.
  2. 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.
  3. html tags contains all tags nexted inside it.
HTML Attribute