An HTML element is everything from the start tag to the end tag. Elements are the building blocks used to define text, buttons, images, and page sections.
Most HTML elements consist of three main parts: an opening tag, the content, and a closing tag.
flowchart LR
A["<p> Start Tag"] --> B["Element Content"]
B --> C["</p> End Tag"]
A & B & C --> D["Complete HTML Element"]
<p>, <h1>, <div>).</p>, </h1>, </div>).HTML elements can contain other elements. This is called nesting. You must close nested elements in the reverse order that you opened them.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML Elements Example</title>
</head>
<body>
<!-- Heading element containing text -->
<h1>Understanding <i>HTML Elements</i></h1>
<!-- Paragraph containing a nested bold element -->
<p>This is a paragraph with <strong>important bold text</strong> inside it.</p>
<!-- Empty element (no closing tag required) -->
<hr>
<!-- Line break empty element -->
<p>First line of text.<br>Second line of text after a line break.</p>
</body>
</html>
Some HTML elements do not contain text content or closing tags. These are called empty elements or void elements.
Common empty elements include:
<br>: Inserts a line break.<img>: Embeds an image file.<hr>: Inserts a horizontal rule line.<input>: Creates a form input field.<meta>: Sets page character encoding or viewport rules.<p><b>Text</b></p> instead of <p><b>Text</p></b>. Overlapping tags cause unexpected DOM rendering errors.</p> tags, omitting closing tags on structural tags like <div> or <section> breaks page layout completely.<P> works like <p>), but lowercase tags are standard across all modern web codebases.Create a simple HTML page with a paragraph (<p>), nest a <strong> tag inside it for emphasis, insert a <hr> horizontal divider line below it, and verify the output in your browser!
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Experiment with the code from this lesson in our interactive playground.