Author : MD TAREQ HASSAN | Updated : 2023/10/25

About html tags

HTML 5 template

In VS Code, type “html:5” and press tab, it will give HTML 5 template as following

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>
<body>
	
</body>
</html>

Explanation:

Comment tag

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>HTML commnet</title>
</head>
<body>
	
  <!-- this is html comment (it will be ignored by the browser) -->

</body>
</html>

br and hr tag

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Break and horizontal line</title>
</head>
<body style="margin: 2em;">
	
  This is a longgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg line, <br /> use break
  
  <br />
  <br />
  
  Line 2

  <br />

  Horizontal line below

  <hr />

  Line 3

</body>
</html>

h tag

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Heading tags</title>
</head>
<body style="margin: 2em;">

	<h1>H1 Heading</h1>

	<h2>H2 Heading</h2>

	<h3>H3 Heading</h3>

	<h4>H4 Heading</h4>

	<h5>H5 Heading</h5>

	<h6>H6 Heading</h6>

</body>
</html>

p tag

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Paragraph tag</title>
</head>
<body style="margin: 2em;">

	<p>This is a paragraph. It can container multiple lines of text.</p>

</body>
</html>

div tag

div tag is container for block of content (block type tag)

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Divition tag</title>
</head>
<body style="margin: 2em;">

  <div>
    This is plain text inside a div

    <h1>h1 tag inside a div</h1>

    <p>This is a paragraph inside a div</p>
  </div>

</body>
</html>

span tag

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Span tag</title>
</head>
<body style="margin: 2em;">

  <span>inline content</span>

  <p>This is a paragraph. <span>this is span inside a p tag</span></p>

</body>
</html>

Text formatting tag

Old way

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Bold, itallic and strike tags</title>
</head>
<body style="margin: 2em;">

  <b>This is bold text</b>

  <i>This is itallic text</i>

  <strike>This is trikethrough text</strike>

</body>
</html>

New way (do not use b, i and strike tags):

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Strong, em and s tags</title>
</head>
<body style="margin: 2em;">

  <strong>Shown as bold text, but it indicates important</strong>
  <br />
  <br />

  <em>Shown as itallic text, but it indicates emphasize</em>
  <br />
  <br />

  <s>Shown as trikethrough text, but it indicates inaccurate text</s>
  <br />
  <br />

  <!-- using u tag to mark spelling error (using css to style underline stroke) -->
  <p>In American English, <u style="text-decoration: #f00 wavy underline;">Colour</u> is wrong, right spelling is "color"</p>

</body>
</html>

u tag (<u> </u>) for text annotations

Example: annotating/indicating spelling errors

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Text annotation</title>
</head>
<body style="margin: 2em;">

  <!-- using u tag to mark spelling error (using css to style underline stroke) -->
  <p>In American English, <u style="text-decoration: #f00 wavy underline;">Colour</u> is wrong, right spelling is "color"</p>

</body>
</html>

tt tag (<tt> </tt>): typewriter text, text will be shown as monospaced

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Typewriter text</title>
</head>
<body style="margin: 2em;">

  <tt>This text will be shown as if written with old typewriter</tt>

</body>
</html>

pre tag

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Pre tag</title>
</head>
<body style="margin: 2em;">

  <pre>
    This text will be shown 
      exactly as
        written
  </pre>

</body>
</html>

sup and sub tag

sup tag

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Superscript tag</title>
</head>
<body style="margin: 2em;">

  <h1>Area of a circle is: πr<sup>2</sup></h1>

</body>
</html>

sub tag

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Subscript tag</title>
</head>
<body style="margin: 2em;">

  <p>The chemical symbol of water is: H<sub>2</sub>O</p>

</body>
</html>

code tag

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Code tag</title>
</head>
<body style="margin: 2em;">


  <code>

    var x = new Pet();

  </code>

</body>
</html>

Quotation tag

q tag (inline quotation)

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Inline quotation with q tag</title>
</head>
<body style="margin: 2em;">

  <!-- q tag is same as using double quotation explicitly -->
  <p>
    I say, <q>everything has a price, either in this life or in after life</q> 
  </p>

</body>
</html>

blockquote tag (block level quotation)

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Blockquote tag</title>
</head>
<body style="margin: 2em;">

<div>
  <blockquote>
    <p>Everything has a price, either in this life or in after life.</p>
  </blockquote>
  <p>- TARIK HASAN</p>
</div>

</body>
</html>

mark tag

Example: use mark element to bring attention to a particular part of a sentance

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Text highlight with mark tag</title>
</head>
<body style="margin: 2em;">

  <p>
    Some people are <mark>color</mark> blind.
  </p>

</body>
</html>

a tag

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Anchor tag</title>
</head>
<body style="margin: 2em;">

  <a href="https://hovermind.com/csharp/" target="_blank">Go to C# page in hovermind.com</a>

</body>
</html>

img tag

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Image tag</title>
</head>
<body style="margin: 2em;">

  <img src="https://unseen-japan.com/wp-content/uploads/2022/09/pixta_58797164_M.jpg" 
  alt="Momiji" width="800" height="400" />

</body>
</html>

List tag

Unordered list (<ul> </ul>)

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Unodered list</title>
</head>
<body style="margin: 2em;">

  <h1>Shopping list</h1>
  <hr />

  <ul>
    <li>Potato</li>
    <li>Tomato</li>
    <li>Onion</li>
    <li>Garlic</li>
    <li>Green chilli</li>
  </ul>

</body>
</html>

Ordered list (<ol> </ol>)

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Odered list</title>
</head>
<body style="margin: 2em;">

  <h1>Todo list</h1>
  <hr />

  <ol>
    <li>Wake up</li>
    <li>Drink coffee</li>
    <li>Join meeting</li>
    <li>Prepare pptx</li>
    <li>Submit pptx</li>
  </ol>

</body>
</html>

table tag

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>HTML table</title>
</head>
<body style="margin: 2em;">

  <h1>Member information table</h1>
  <hr />

  <table>

    <!-- head section of table -->
    <thead>

      <tr>
        <th>No.</th>
        <th>Name</th>
        <th>Profession</th>
      </tr>
      
    </thead>

    <!-- body section of table -->
    <tbody>

      <tr>
        <td>1</td>
        <td>HASAN</td>
        <td>Technical Architect</td>
      </tr>

      <tr>
        <td>2</td>
        <td>Meherun</td>
        <td>Housewife</td>
      </tr>

      <tr>
        <td>3</td>
        <td>Salma</td>
        <td>Housewife</td>
      </tr>

      <tr>
        <td>4</td>
        <td>Ibrahim</td>
        <td>Kaishain</td>
      </tr>

      <tr>
        <td>5</td>
        <td>Nazmul</td>
        <td>Kaishain</td>
      </tr>

      <tr>
        <td>6</td>
        <td>Soharaf</td>
        <td>Kaishain</td>
      </tr>

    </tbody>

  </table>

</body>
</html>