HTML Elements

In HTML, an element is the complete “building block” of a webpage. People often use the words “tag” and “element” interchangeably, but there is a technical difference: an element is the collection of the opening tag, the attributes, the content, and the closing tag.

Anatomy of an HTML Element

Most elements follow a specific structure. If you miss one part (like a closing tag), it can break the layout of the entire page.
				
					<p class="text-blue">Lorem Ipsum is a dummy text.</p>
				
			

Categories of Elements

HTML elements are categorized based on how they behave in the document flow. Understanding this is the secret to mastering layouts.

1. Block-level Elements

These elements always start on a new line and take up the full width available (stretching to the left and right as far as they can).

2. Inline Elements

These elements do not start on a new line. They only take up as much width as necessary for their content.

3. Void (Empty) Elements

These elements do not have any content and therefore do not have a closing tag.

Element Nesting

Elements can be placed inside other elements. This is called nesting. It is vital to close your tags in the reverse order they were opened to maintain a proper “tree” structure.

✅ Correct Nesting:

				
					<p>This is <strong>bold</strong> text.</p>
				
			

❌ Incorrect Nesting:

				
					<p>This is <strong>bold text.</p></strong>
				
			

Case Sensitive

HTML elements are not case-sensitive <P> means the same as <p>, which means we can use both upper or, lower case letters in the tag.

				
					<P>HTML is not case sensitive i.e we can use both upper or, lower case letters in the tags.</p>
				
			

Quick Summary Table

FeatureBlock-levelInline
New LineStarts on a new lineDoes not start on a new line
WidthFull width of containerOnly as wide as the content
NestingCan contain Block or InlineUsually only contains other Inline
Example<div>, <header>, <p><span>, <b>, <a>