HTML Text Elements Guide

Text elements form the core of most HTML documents. This guide covers headings, paragraphs, and various text formatting elements that help structure and style your content.

1. Headings

HTML provides six levels of headings, from <h1> (most important) to <h6> (least important). Headings create a hierarchical structure for your content.

<h1>Heading Level 1</h1> <h2>Heading Level 2</h2> <h3>Heading Level 3</h3> <h4>Heading Level 4</h4> <h5>Heading Level 5</h5> <h6>Heading Level 6</h6>

Heading Level 1

Heading Level 2

Heading Level 3

Heading Level 4

Heading Level 5
Heading Level 6
Best Practices:
  • Use only one <h1> per page, usually for the main title/topic
  • Don't skip heading levels (e.g., don't go from <h2> to <h4> without an <h3> in between)
  • Use headings to create a logical hierarchy of content
  • Keep headings concise and descriptive

2. Paragraphs

The <p> element represents a paragraph of text. Browsers automatically add space before and after paragraphs.

<p>This is a paragraph of text. Paragraphs are block-level elements, which means they create a new block of content.</p> <p>This is another paragraph. Notice how browsers automatically add spacing between paragraphs.</p>

This is a paragraph of text. Paragraphs are block-level elements, which means they create a new block of content.

This is another paragraph. Notice how browsers automatically add spacing between paragraphs.

White Space and Line Breaks

<p> Extra spaces and line breaks in HTML are collapsed to a single space. </p> <p>To force a line break, use the <br> tag.<br>This text appears on a new line.</p>

Extra spaces and line breaks in HTML are collapsed to a single space.

To force a line break, use the <br> tag.
This text appears on a new line.

Note: Use <br> sparingly and only when a line break is part of the content (like in addresses or poetry). Don't use it for creating space between elements - use CSS margins instead.

3. Text Formatting Elements

Semantic Formatting Elements

These elements add semantic meaning to the text they enclose:

<strong>Strong importance</strong>
Strong importance

Indicates strong importance, seriousness, or urgency.

<em>Emphasized text</em>
Emphasized text

Indicates emphasis or stress.

<mark>Marked or highlighted text</mark>
Marked or highlighted text

Represents text marked or highlighted for reference.

<del>Deleted text</del>
Deleted text

Represents text that has been deleted.

<ins>Inserted text</ins>
Inserted text

Represents text that has been inserted.

<sub>Subscript</sub> text
Subscript text

Represents subscript text (appearing below the baseline).

<sup>Superscript</sup> text
Superscript text

Represents superscript text (appearing above the baseline).

<abbr title="HyperText Markup Language">HTML</abbr>
HTML (hover to see the full title)

Represents an abbreviation or acronym with optional title attribute.

Stylistic Formatting Elements

These elements are primarily for styling purposes, without specific semantic meaning:

<b>Bold text</b>
Bold text

Represents text stylistically bold without added importance.

<i>Italic text</i>
Italic text

Represents text stylistically italic without emphasis.

<u>Underlined text</u>
Underlined text

Represents text with non-semantic underline (use with caution as it can be confused with links).

<small>Small text</small>
Small text

Represents smaller text like side-comments and fine print.

Semantic vs. Stylistic: When possible, use semantic elements (<strong>, <em>) rather than purely stylistic ones (<b>, <i>). This improves accessibility and conveys meaning to screen readers.

4. Quotations and Citations

<blockquote cite="https://www.example.com"> <p>This is a blockquote. It represents a section that is quoted from another source.</p> </blockquote>

This is a blockquote. It represents a section that is quoted from another source.

<p>According to the MDN documentation, <q>The HTML <q> element indicates that the enclosed text is a short inline quotation.</q></p>

According to the MDN documentation, The HTML <q> element indicates that the enclosed text is a short inline quotation.

<p><cite>The Great Gatsby</cite> was written by F. Scott Fitzgerald.</p>

The Great Gatsby was written by F. Scott Fitzgerald.

Element Description Use Case
<blockquote> Block-level quotation Longer quotes that deserve their own block
<q> Inline quotation Short quotes within a paragraph
<cite> Citation or reference Titles of works (books, movies, etc.)

5. Code and Preformatted Text

<p>The <code>getElementsByTagName()</code> method returns a collection of elements.</p>

The getElementsByTagName() method returns a collection of elements.

<pre> function greet(name) { console.log("Hello, " + name + "!"); } greet("World"); </pre>
  function greet(name) {
    console.log("Hello, " + name + "!");
  }
  
  greet("World");
Element Description Use Case
<code> Represents computer code Variable names, function names, etc.
<pre> Preformatted text Code blocks or any text where spacing is important
<kbd> Keyboard input Represent keyboard keys or input (e.g., Ctrl+S)
<samp> Sample output Represent output from a program
<var> Variable Represent variables in math or programming

6. Generic Text Containers

The span Element

<p>This is a paragraph with <span style="color: red;">some red text</span> inside it.</p>

This is a paragraph with some red text inside it.

The <span> element is an inline generic container with no inherent meaning. It's primarily used to apply styles or scripting to a specific portion of text.

The div Element

<div style="background-color: #f0f0f0; padding: 10px;"> <h3>This is a heading inside a div</h3> <p>This is a paragraph inside a div.</p> </div>

This is a heading inside a div

This is a paragraph inside a div.

The <div> element is a block-level generic container with no inherent meaning. It's primarily used for styling or to group elements together.

Note: Where possible, use semantic HTML5 elements (like <article>, <section>, <header>, etc.) instead of generic <div> elements. Reserve <div> and <span> for when no other semantic element is appropriate.

7. Time and Date Elements

<p>The event starts at <time>20:00</time>.</p> <p>The concert takes place on <time datetime="2025-07-15">July 15, 2025</time>.</p> <p>The store opens at <time datetime="09:00">9 AM</time> and closes at <time datetime="21:00">9 PM</time>.</p>

The event starts at .

The concert takes place on .

The store opens at and closes at .

The <time> element represents a specific time or date. The datetime attribute provides the time/date in a machine-readable format.

Tip: The datetime attribute should be in a valid format:
  • Date: YYYY-MM-DD
  • Time: HH:MM:SS
  • Date and time: YYYY-MM-DDTHH:MM:SS
  • Time zone can be added with +HH:MM or Z for UTC

8. Ruby Text (East Asian Annotations)

<ruby> 漢 <rt>かん</rt> 字 <rt>じ</rt> </ruby>
かん

The <ruby> element represents small annotations that are rendered above, below, or beside base text, usually used for East Asian typography. The <rt> element specifies the ruby text component.

9. Line Breaks and Horizontal Rules

Line Break

<p>This text contains<br>a line break.</p>

This text contains
a line break.

Horizontal Rule

<p>Text above the horizontal rule.</p> <hr> <p>Text below the horizontal rule.</p>

Text above the horizontal rule.


Text below the horizontal rule.

The <hr> element represents a thematic break between paragraph-level elements. It's displayed as a horizontal line.

10. Best Practices