Text & Content Elements
Checking access...
Text is the primary content of most web pages. HTML provides a rich set of elements for structuring and formatting text meaningfully.
Headings: <h1> to <h6>
Headings create a hierarchical structure for your content, like chapters in a book.
<h1>Main Page Title</h1><h2>Section Heading</h2><h3>Sub-section Heading</h3><h4>Sub-sub-section Heading</h4><h5>Minor Heading</h5><h6>Smallest Heading</h6>Heading Rules
| Rule | Why |
|---|---|
One <h1> per page | It represents the main topic — search engines use it for SEO |
| Don’t skip levels | Go h1 → h2 → h3, not h1 → h3 (confuses screen readers) |
| Use for structure, not size | If you want bigger text, use CSS, not a higher heading level |
<!-- ❌ Wrong: skipping levels for visual size --><h1>My Site</h1><h3>Contact</h3>
<!-- ✅ Correct: proper hierarchy --><h1>My Site</h1><h2>Contact</h2>Paragraphs: <p>
Paragraphs wrap blocks of text:
<p>This is a paragraph of text. Browsers automatically add space before and after paragraphs.</p><p>This is another paragraph. Notice the vertical gap between them.</p>- Browsers collapse multiple whitespace characters into a single space
- Line breaks in your HTML source do not create new lines in the browser
<p> This text is on multiple lines in the editor but appears as one line in the browser.</p>Bold and Italic: Semantic vs Presentational
HTML provides both semantic (meaningful) and presentational (visual) elements:
<!-- Semantic (recommended) --><strong>This text is important</strong> <!-- Bold + indicates importance --><em>This text is emphasized</em> <!-- Italic + indicates emphasis -->
<!-- Presentational (avoid unless purely stylistic) --><b>This is just bold</b> <!-- Bold, no meaning --><i>This is just italic</i> <!-- Italic, no meaning -->Tip
Use <strong> and <em> by default. They convey meaning to screen readers and search engines. Use <b> and <i> only when the styling has no semantic importance (like product names or foreign words).
Line Breaks: <br>
Use <br> for line breaks inside a paragraph:
<p> 123 Main Street<br> Springfield, IL 62701<br> USA</p><br>is a void element (no closing tag)- Do NOT use
<br>to create spacing between paragraphs — use<p>for that
Horizontal Rule: <hr>
<hr> creates a thematic break (visual line):
<h2>Section One</h2><p>Content for section one.</p>
<hr>
<h2>Section Two</h2><p>Content for section two.</p><hr>represents a thematic shift, not just a decorative line- Can be styled with CSS for different appearances
Subscript and Superscript
<p>H<sub>2</sub>O is water.</p><p>Einstein's famous equation: E = mc<sup>2</sup></p><sub> for subscripts (chemical formulas, footnotes) <sup> for superscripts (exponents, ordinal numbers like 1st).
Blockquotes
For quoted content from another source:
<blockquote cite="https://example.com/source"> <p>The only way to do great work is to love what you do.</p> <footer>— Steve Jobs</footer></blockquote>- Browsers typically indent blockquotes
- The
citeattribute tells the source URL (not visible to users but machine-readable) - Short inline quotes use
<q>:
<p>As they say, <q>knowledge is power</q>.</p>Preformatted Text: <pre>
<pre> preserves whitespace and uses a monospace font:
<pre> function hello() { console.log("Hello, world!"); }</pre>Perfect for code snippets, ASCII art, or any text where spacing matters.
Code Elements
<p>Use the <code>console.log()</code> function to print to the console.</p>
<p>When saving, press <kbd>Ctrl+S</kbd> (or <kbd>Cmd+S</kbd> on Mac).</p>
<p>The <var>x</var> variable represents the user's age.</p>
<p>Program output: <samp>Hello, World!</samp></p>| Element | Purpose |
|---|---|
<code> | Inline code snippet |
<kbd> | Keyboard input |
<var> | Variable name |
<samp> | Program output |
HTML Entities (Special Characters)
Some characters have special meaning in HTML and must be written as entities:
| Character | Entity | Why |
|---|---|---|
< | < | Would be interpreted as HTML tag start |
> | > | Would be interpreted as HTML tag end |
& | & | Would be interpreted as entity start |
" | " | Would end an attribute value |
' | ' | Would end an attribute value |
| Non-breaking space | | Prevents line break between words |
<p>HTML tags use <angle brackets>.</p><p>At the store, buy bread & milk.</p><p>Copyright © 2026 My Company</p><p>Price: $1,500 — Limited time offer</p>Common named entities: © (©), ® (®), ™ (™), — (—), → (→).
Try It Yourself
Create a page that uses:
- An
<h1>for the page title and<h2>for at least two sections - Two paragraphs of text in each section
- A
<strong>and an<em>within your paragraphs - An address with
<br>line breaks - A
<hr>between sections - A
<blockquote>from a famous person - A code example inside
<pre>and<code>tags - At least two HTML entities
Key Takeaways
- Headings create a structural hierarchy — one
<h1>per page, don’t skip levels - Use
<strong>and<em>for semantic bold/italic instead of<b>/<i> <br>creates line breaks inside paragraphs;<hr>creates section dividers<pre>preserves whitespace — use it for code or formatted text- HTML entities (
<,&, etc.) represent special characters that would otherwise be interpreted as code - Semantic elements help search engines and screen readers understand your content