← All topics

HTML REFERENCE · 02

Text and Headings

HTML text elements describe the role of your words: a heading introduces a topic, a paragraph contains prose, and emphasis changes how part of a sentence should be understood.

Choose elements for their meaning. Use CSS to change their size, color, spacing, or appearance.

Text elements at a glance

Element What it means When to use it
h1–h6 Six heading levels that describe the hierarchy of topics on a page. Use h1 for the main subject, h2 for major sections, and h3 for subsections within those sections. Continue deeper only when the content requires it.
p A paragraph: a related block of written content. Use for introductions, explanations, and descriptions. Give each separate paragraph its own p element.
strong Marks strong importance, seriousness, or urgency. Usually displayed in bold. Use for important warnings or instructions, such as “Do not disconnect the power.”
em Marks stress emphasis within a sentence. Usually displayed in italics. Use when stressing a word changes the intended meaning or tone of the sentence.
b Draws attention without expressing extra importance or stress emphasis. Use for a keyword or other text needing attention. Use CSS when the goal is only a visual bold effect.
i Marks text in an alternate voice or category, such as a technical term or scientific name. Use when the text has that distinct role. Use CSS when you only want an italic appearance.
br Inserts a line break within content. It is a void element with no closing tag. Use where the line break is meaningful, such as an address or poem. Do not repeat it to create page spacing.
hr Represents a thematic break between paragraphs. Usually displayed as a horizontal line. Use when the topic or scene changes. Use CSS for a purely decorative divider.
small Represents side comments or small print. Use for disclaimers, copyright notices, or similar supporting information. It is not a general tool for shrinking text.
mark Highlights text relevant to the current context. Usually displayed with a highlighted background. Use for a matching search term or a relevant passage within a quotation.
blockquote Represents an extended quotation from another source. Use for a quoted passage that stands separately from the surrounding prose.
q Represents a short quotation within a sentence. Browsers normally supply quotation marks. Use for a short quoted phrase inside a paragraph.
code Identifies a fragment of computer code. Usually displayed in a monospace font. Use when discussing code, such as an HTML tag, a function name, or a code expression.
pre Preserves spaces and line breaks in its text. Use for preformatted text. Combine it with code when displaying a multiline code example.
sub / sup Represent subscript and superscript notation. Use for conventions such as chemical formulas and mathematical exponents: H₂O and x².

Understanding heading levels

Heading levels form an outline. A simple page normally has one h1 identifying its main subject. Each major topic beneath it uses h2. A smaller topic within an h2 section uses h3.

Multiple sections can share the same heading level. For example, “About Me” and “My Interests” can both be h2 because neither is a subsection of the other.

Code

<h1>Nikki's Profile</h1>

<h2>About Me</h2>
<p>I enjoy building websites.</p>

<h2>My Interests</h2>

<h3>Climbing</h3>
<p>I enjoy spending time at the climbing gym.</p>

<h3>Coding</h3>
<p>I am refreshing my HTML skills.</p>

Output

Nikki's Profile

About Me

I enjoy building websites.

My Interests

Climbing

I enjoy spending time at the climbing gym.

Coding

I am refreshing my HTML skills.

Do not choose h4 simply because you want smaller text. Choose the correct level for the outline, then style it with CSS. A logical heading structure also helps screen-reader users navigate the document.

Paragraphs and whitespace

Browsers normally collapse repeated spaces and source-code line breaks into a single space in ordinary text. Pressing Enter several times in your HTML does not create several visible paragraph breaks.

Code

<p>These words
       are on different lines
       in the source.</p>

<p>This is a separate paragraph.</p>

Output

These words are on different lines in the source.

This is a separate paragraph.

Use separate p elements for separate paragraphs. Use CSS margin or padding to adjust their spacing. A paragraph cannot contain headings or another paragraph.

Importance versus emphasis

Strong and em can look similar to b and i, but their meanings differ. Strong expresses importance; em stresses particular words.

Code

<p><strong>Warning:</strong> This action deletes the file.</p>

<p>I asked for the <em>blue</em> folder.</p>

<p><b>Keyword:</b> semantic HTML</p>

<p>The scientific name is <i>Felis catus</i>.</p>

Output

Warning: This action deletes the file.

I asked for the blue folder.

Keyword: semantic HTML

The scientific name is Felis catus.

Appearance alone does not tell you which element is appropriate. Ask what the text means in context. Assistive technology does not necessarily announce every emphasis element differently.

Line breaks and thematic breaks

Br continues the same content on a new line. Hr indicates a change of topic. Neither requires a closing tag.

Code

<p>
  Nikki Brooks<br>
  San Diego, California
</p>

<hr>

<p>Now we are discussing a different topic.</p>

Output

Nikki Brooks
San Diego, California


Now we are discussing a different topic.

Repeated br tags are not a layout system. Use paragraphs for paragraphs and CSS for spacing.

Small print, highlighting, and notation

These elements identify specific roles within text. Their default appearance helps communicate those roles, but CSS can change that appearance.

Code

<p><small>Offer subject to availability.</small></p>

<p>Search result: Learn <mark>HTML</mark> basics.</p>

<p>Water: H<sub>2</sub>O</p>

<p>Squared: x<sup>2</sup></p>

Output

Offer subject to availability.

Search result: Learn HTML basics.

Water: H2O

Squared: x2

Quotations

Blockquote identifies a quoted passage. Q identifies a short quotation inside a sentence. Do not use blockquote just to indent ordinary text.

Code

<blockquote>
  <p>One small step at a time.</p>
</blockquote>

<p>My friend said, <q>Keep learning.</q></p>

Output

One small step at a time.

My friend said, Keep learning.

The sentences above are demonstration quotations. For a real quotation, provide appropriate source attribution. An attribution belongs outside the quoted passage.

Showing code as text

Code identifies computer code. Pre preserves its whitespace. Together, they work well for multiline code examples.

To display an HTML tag instead of creating an element, write &lt; for the opening angle bracket and &gt; for the closing angle bracket.

What you write

<p>Use <code>&lt;p&gt;</code> for a paragraph.</p>

<pre><code>const topic = "HTML";
console.log(topic);</code></pre>

Output

Use <p> for a paragraph.

const topic = "HTML";
console.log(topic);

The JavaScript above is displayed as text. Putting code inside code or pre does not execute it. This guide's stylesheet also wraps long code lines to keep them readable.

Study questions

Answer first, then click to reveal the explanation.

1. How do I choose between h2 and h3?

Choose h2 for a major section beneath the page's main heading. Choose h3 for a subsection within an h2 section. Their role in the outline matters more than their font size.

2. Can a page have several h2 headings?

Yes. Major sections at the same level can each have an h2. For example, About Me and My Interests can be sibling sections.

3. Why not make every heading a bold paragraph?

Bold styling changes appearance but does not give a paragraph heading semantics. Real headings describe the document outline and support heading-based navigation in assistive technology.

4. What happens to extra spaces in ordinary paragraph text?

They normally collapse into a single space. Source-code line breaks also normally become whitespace rather than visible line breaks. CSS can change whitespace handling.

5. How do strong and b differ?

Strong expresses importance, seriousness, or urgency. B draws attention without adding that importance. Both usually look bold by default.

6. When should I use em instead of i?

Use em to stress a word in a sentence. Use i for an alternate voice or category, such as a scientific name. Use CSS if you only want an italic appearance.

7. Should I use several br tags to separate sections?

No. Br represents a meaningful line break within content. Use appropriate section structure and CSS spacing instead.

8. Is hr only a decorative line?

No. It represents a thematic break. If you only want a visual line, a CSS border may be more appropriate.

9. What is the difference between strong and mark?

Strong identifies importance. Mark identifies relevance in a particular context, such as a search result matching the user's search term.

10. Why use pre and code together?

Code identifies the content as computer code. Pre preserves whitespace and line breaks. They provide different meanings and work together for formatted code examples.

11. How do I display <h1> as text?

Write &lt;h1&gt; in your HTML. The character references display angle brackets without creating a heading element.

12. When should I use blockquote rather than q?

Use blockquote for an extended, separate quotation. Use q for a short quotation within a sentence. Neither should be chosen only for its visual appearance.