0
0
HTMLmarkup~5 mins

Opening and closing tags in HTML

Choose your learning style9 modes available
Introduction

Opening and closing tags tell the browser where an element starts and ends. They help organize content on a webpage.

When you want to add a paragraph of text on a webpage.
When you want to create a heading to title a section.
When you want to group content inside a container like a div.
When you want to add emphasis or style to some text.
When you want to add a list of items.
Syntax
HTML
<tagname>Content goes here</tagname>
The opening tag is written as <tagname>.
The closing tag is written as </tagname> with a slash before the tag name.
Examples
A paragraph tag with opening <p> and closing </p> tags.
HTML
<p>This is a paragraph.</p>
A heading tag with opening <h1> and closing </h1> tags.
HTML
<h1>Welcome to my site</h1>
A div tag used to group content with opening and closing tags.
HTML
<div>Some content inside a container</div>
Sample Program

This example shows a heading, paragraphs, and a div container all using opening and closing tags to organize content.

HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Opening and Closing Tags Example</title>
</head>
<body>
  <h1>My First Heading</h1>
  <p>This is a paragraph inside opening and closing tags.</p>
  <div>
    <p>Another paragraph inside a div container.</p>
  </div>
</body>
</html>
OutputSuccess
Important Notes

Always match the opening and closing tag names exactly.

Some tags like <br> or <img> do not need closing tags; these are called self-closing tags.

Summary

Opening tags start an element, closing tags end it.

Tags must match to keep the webpage structure clear.

Using tags correctly helps browsers show your content properly.