HTML Elements
Elements form a tree. A paragraph can contain an emphasized phrase, while a section can contain the paragraph. Correct nesting preserves these relationships for browsers and assistive technology.
How it works
- Close nested elements in reverse order: the last element opened is the first one closed. Indentation helps expose the structure.
- A tag is the markup token such as <p>; the element includes its tags and content. Void elements such as br and img do not wrap content.
- Browsers repair invalid markup, but their repaired DOM may differ from your source. Use developer tools to inspect the actual tree.
A practical example
<section>
<h2>Before you arrive</h2>
<p>Please bring <strong>a reusable cup</strong>.</p>
<p>Questions?<br>Ask at the welcome desk.</p>
</section>
The strong element belongs inside the first paragraph. The line break affects only the second paragraph and does not create another paragraph.