HTML elements are the basic building blocks of a webpage. They define how content is structured and organized using tags. A typical HTML element consists of an opening tag, content, and a closing tag.
- Elements can contain text, attributes, and other nested elements.
- They follow a parent-child hierarchy to organize webpage content.
- Some elements, known as void elements, do not have closing tags or contain child content.
Example of HTML Elements
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p>Welcome to GeeksforGeeks!</p>
</body>
</html>
Here,<p>is the opening tag,Welcome to GeeksforGeeks!is the content, and</p>is the closing tag.
Case Sensitivity
HTML tags are not case-sensitive, meaning <B> and <b> represent the same element. However, using lowercase tags is recommended for consistency and readability.
Nested HTML Elements
Nested HTML elements occur when one element is placed inside another, creating a parent-child relationship. This hierarchy forms the structure of the DOM (Document Object Model) and helps organize webpage content.
Example:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div style="text-align:center">
<h1>GeeksforGeeks</h1>
<p>Computer Science Portal</p>
</div>
</body>
</html>
Here, <div> is the parent element, while <h1> and <p> are its child elements.Necessary to Add an End Tag
Most HTML elements require closing tags to define their content boundaries. However, some elements have optional end tags, which browsers can infer under specific conditions.
- Elements such as <div>, <h1>, and <span> require closing tags.
- Elements such as <p>, <li>, and <td> have optional end tags under specified conditions.
Using closing tags wherever required helps maintain readable and well-structured HTML.
Example:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h2>Welcome to GeeksforGeeks</h2>
<p>Hi Geeks!</p>
</body>
</html>

HTML Empty Elements (Void Elements)
Void elements are HTML elements that cannot contain child content and do not have closing tags. They perform specific functions, such as inserting line breaks, embedding images, and linking external resources.
Examples:
- <br>: Inserts a line break.
- <hr>: Creates a thematic break.
- <img>: Embeds an image.
- <link>: Links external resources, such as stylesheets.
- <input>: Creates an input control
Example:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h2>Welcome to GeeksforGeeks</h2>
<br>
<p>Hello Geeks!</p>
<hr>
</body>
</html>
Block-Level Elements and Inline Elements
HTML elements are commonly classified as block-level or inline based on their default display behavior.
1. Block-Level Elements
Block-level elements typically start on a new line and occupy the available width of their containing block.
Examples:
- <div>: Groups other HTML elements.
- <p>: Defines a paragraph.
- <h1> to <h6>: Define headings.
- <ul> and <ol>: Create unordered and ordered lists.
- <section> and <article>: Define semantic sections of a webpage.
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div>
<h2>GeeksforGeeks</h2>
<p>This content is inside a div.</p>
</div>
<table border="1">
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>David</td>
<td>22</td>
</tr>
</table>
</body>
</html>
2. Inline Elements
Inline elements typically flow within the surrounding text and occupy only the space required by their content.
Examples:
- <span>: Groups inline content.
- <a>: Creates hyperlinks.
- <img>: Embeds an image.
- <strong> and <b>: Represent important text and visually bold text, respectively.
- <em> and <i>: Represent emphasized text and text in an alternate voice or mood, respectively.
- <br>: Inserts a line break.
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p>
This is a <span>span element</span> used for styling text.
</p>
<p>
<strong>Strong text</strong> and <b>bold text</b> are inline elements.
<em>Emphasized text</em> and <i>italic text</i> are also inline.
</p>
<form>
<label>Name:</label>
<input type="text" placeholder="Enter your name">
</form>
</body>
</html>
Note: The default display behavior of these elements can be changed using CSS properties such as display.
Difference Between <b> and <strong> Tag
| Feature | <b> Tag | <strong> Tag |
|---|---|---|
| Purpose | Draws attention to text without indicating additional importance. | Indicates that the text has strong importance or urgency. |
| Semantic Meaning | Does not convey additional semantic importance. | Conveys semantic importance. |
| Accessibility | Does not inherently indicate importance to screen readers. | Screen readers may convey the importance through their pronunciation or settings. |
SEO | Does not indicate content importance to search engines. | Provides semantic information that may help search engines understand content. |
Also Check:
HTML Block and Inline Elements

