HTML Basics
HTML Elements
An HTML element is a complete unit of content, made of an opening tag, some content, and a closing tag. Understanding elements is the heart of learning HTML.
What is an HTML Element?
An element is everything from the opening tag to the closing tag, including the content in between. For example, <p>Hello</p> is a paragraph element.
<p>This is a paragraph.</p>
<!--
<p> = opening tag
content = This is a paragraph.
</p> = closing tag
-->Empty (Void) Elements
Some elements have no content and therefore no closing tag. These are called empty or void elements. Common examples are the line break and the image tag.
<br>
<hr>
<img src="cat.jpg" alt="A cat">Nesting Elements
Elements can be placed inside other elements. This is called nesting. Always close inner elements before outer ones to keep the structure valid.
<p>This is <strong>very</strong> important.</p>Do not overlap tags. Writing <p><strong>text</p></strong> is invalid because the strong element is not closed before the paragraph. Always close in reverse order.
