Skip to main content

Skillber v1.0 is here!

Learn more

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

RuleWhy
One <h1> per pageIt represents the main topic — search engines use it for SEO
Don’t skip levelsGo h1 → h2 → h3, not h1 → h3 (confuses screen readers)
Use for structure, not sizeIf 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 cite attribute 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>
ElementPurpose
<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:

CharacterEntityWhy
<&lt;Would be interpreted as HTML tag start
>&gt;Would be interpreted as HTML tag end
&&amp;Would be interpreted as entity start
"&quot;Would end an attribute value
'&apos;Would end an attribute value
Non-breaking space&nbsp;Prevents line break between words
<p>HTML tags use &lt;angle brackets&gt;.</p>
<p>At the store, buy bread &amp; milk.</p>
<p>Copyright &copy; 2026 My Company</p>
<p>Price: $1,500 &nbsp;&nbsp; Limited time offer</p>

Common named entities: &copy; (©), &reg; (®), &trade; (™), &mdash; (—), &rarr; (→).

Try It Yourself

Create a page that uses:

  1. An <h1> for the page title and <h2> for at least two sections
  2. Two paragraphs of text in each section
  3. A <strong> and an <em> within your paragraphs
  4. An address with <br> line breaks
  5. A <hr> between sections
  6. A <blockquote> from a famous person
  7. A code example inside <pre> and <code> tags
  8. 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 (&lt;, &amp;, etc.) represent special characters that would otherwise be interpreted as code
  • Semantic elements help search engines and screen readers understand your content