HTML
📌 What Are HTML Elements (Tags)?
In HTML, an element (tag) is the basic building block of a web page. An element generally consists of three parts:
- Opening tag
- Content
- Closing tag
For example:
<h1>Hello World</h1>
Here:
-
<p>→ opening tag -
</p>→ closing tag - Hello world → content
This structure helps the browser understand that the text is a paragraph.
Empty Elements
Some HTML tags do not contain any content and do not require a closing tag. These are called empty elements.
Example:
<br>
This tag is used to create a line break and does not hold any content.
Nested Elements
In HTML, elements can be placed inside other elements. This is called nesting and allows the page structure to be organized in layers.
Example:
<!DOCTYPE html>
<html>
<body>
<h1>Heading</h1>
<p>A paragraph.</p>
</body>
</html>
Here:
-
<html>is the outermost container -
<body>is inside it -
<h1>and<p>are inside<body>
Importance of Closing Tags
In some cases, browsers may try to render a page even if closing tags are missing. However, this can lead to:
- Incorrect layouts
- Unexpected behavior
- Messy code
For example :
<p>This is a paragraph
<p>This is another paragraph
Writing code this way is risky. The correct approach is:
<p>This is a paragraph</p>
<p>This is another paragraph</p>
Case Sensitivity
HTML tags are not case-sensitive. This means:
<P>This is a paragraph</P>
and
<p>This is a paragraph</p>
work exactly the same.
However, in modern web standards and professional practice, using lowercase tags is recommended. This makes the code more readable and consistent.
