HTML elements are categorized into two types based on their default behavior:
1️⃣ Block Elements → Start on a new line and take up the full width.
2️⃣ Inline Elements → Stay in the same line and take only as much space as needed.
✔ A block element always starts on a new line.
✔ It takes the full width of its container.
✔ Used for structuring content like paragraphs, headings, and sections.
| Element | Description |
|---|---|
<div> |
Generic container for layout |
<p> |
Paragraph of text |
<h1> to <h6> |
Headings (H1 is the largest, H6 is the smallest) |
<ul> / <ol> |
Lists (unordered & ordered) |
<table> |
Table for displaying data |
<section> |
Section of content |
<article> |
Article or independent content |
<aside> |
Sidebar or additional info |
<header> |
Header section of a webpage |
<footer> |
Footer section of a webpage |
<p>This is a paragraph.</p>
<h2>This is a heading</h2>
<div>This is a block container</div>
✔ Each element starts on a new line and stretches across the page.
✔ An inline element does not start on a new line.
✔ It only takes up the space it needs.
✔ Used for styling and formatting inside block elements.
| Element | Description |
|---|---|
<span> |
Generic inline container for styling |
<a> |
Anchor (hyperlink) |
<b> / <strong> |
Bold text |
<i> / <em> |
Italic or emphasized text |
<u> |
Underlined text |
<small> |
Smaller text |
<mark> |
Highlighted text |
<code> |
Displays code in monospace font |
<img> |
Embeds an image |
<br> |
Line break (forces text to a new line) |
<input> |
Form input field |
<p>This is <strong>bold</strong> and <i>italic</i> text.</p>
<a href="#">Click here</a>
✔ Inline elements stay in the same line and only use necessary space.
| Feature | Block Elements | Inline Elements |
|---|---|---|
| Starts on a new line? | ✅ Yes | ❌ No |
| Takes full width? | ✅ Yes | ❌ No (only needed space) |
| Used for layout? | ✅ Yes | ❌ No |
| Common Examples | <div>, <p>, <h1> |
<span>, <a>, <b> |
You can use inline elements inside block elements, but not vice versa.
<p>This is a <span style="color: red;">red</span> word.</p>
✔ The <span> element stays inline inside the <p> block element.