30 Mins

3. Text Elements

Headings (h1-h6)

The <h1> through <h6> elements represent six levels of section headings, with <h1> being the highest rank. They provide the document outline structure, which is vital for navigation.

Use them hierarchically and never skip levels for visual style. Screen readers use these to allow users to jump between sections, and search engines prioritize them to understand content relevance.

Operator Note: Only use one <h1> per page to represent the primary topic, as multiple <h1> tags can confuse screen reader users and dilute SEO focus.
HTML
<h1>Main Title</h1>
<h2>Section Header</h2>
<h3>Subsection</h3>

Paragraphs

The <p> element is a block-level container for a block of text. It is the fundamental building block for narrative content on a webpage.

Avoid using <p> elements to create vertical spacing; use CSS margins or padding instead to maintain semantic integrity and proper document structure.

Operator Note: Never nest other block-level elements like <div> or <h1> inside a <p> tag; it is invalid HTML and will cause unexpected rendering issues.
HTML
<p>This is a paragraph of text designed to contain information.</p>

Line Breaks & Horizontal Rules

The <br> tag forces a line break within text, while the <hr> tag represents a thematic break between paragraph-level elements.

Avoid using <br> to manage visual whitespace; it is intended only for lines where the line break is part of the content, such as in an address or a poem.

Operator Note: Use <hr> strictly for thematic shifts, not for visual decoration; if you need a decorative line, use CSS borders on container elements instead.
HTML
<p>
  Line one
  <br />
  Line two
</p>
<hr />

Bold & Strong

The <b> element indicates text that is stylistically different, while the <strong> element indicates strong importance, seriousness, or urgency.

Always prefer <strong> for screen readers, as it communicates the emphasis vocally, whereas <b> is treated as standard text by assistive technologies.

Operator Note: Use <strong> for semantic importance and reserve <b> only when you need a bold style without implying extra weight.
HTML
<strong> This text is critically important. </strong>
<b> This text is just bold. </b>

Italic & Emphasis

The <i> element represents text in an alternative voice or mood, while the <em> element indicates stress emphasis that changes the meaning of a sentence.

Similar to the bold/strong distinction, <em> conveys auditory importance to screen readers, while <i> is purely presentational or for specific typographic conventions like scientific names.

Operator Note: Use <em> when you want to change the tone or stress of a word, as this helps search engines and screen readers interpret the intent correctly.
HTML
<em> I really mean this. </em> <i> This is a technical term in italics. </i>

Small, Mark, Superscript, Subscript

The <small> tag denotes side comments or legal disclaimers. The <mark> element indicates text highlighted for reference. <sup> and <sub> handle superscripts and subscripts.

These tags provide specific semantic meaning beyond standard text. For example, <sup> is standard for citations, while <mark> indicates content of interest due to user activity.

Operator Note: Do not use <small> to manage font sizes throughout your site; use CSS font-size for that purpose.
HTML
<small> Legal disclaimer. </small>
<mark> Highlighted </mark>
A
<sup> 2 </sup>
+ B
<sub> 1 </sub>

Quotes & Blockquotes

The <blockquote> element represents extended quotations, while <q> is for short, inline quotations. They indicate that the contained content originates from another source.

Browsers automatically add quotation marks around <q> elements based on the language setting, making it the preferred choice for accessibility compliance.

Operator Note: Always use the cite attribute on blockquotes and inline quotes to provide a URL source, which helps browsers and search engines verify the origin.
HTML
<blockquote>Extended quote here.</blockquote>
<p>
  He said
  <q> Hello </q>
  to everyone.
</p>

Code & Preformatted Text

The <code> element represents a fragment of computer code. The <pre> element displays text exactly as formatted in the source, preserving white space and line breaks.

When displaying code blocks, it is common to wrap <code> inside <pre> to ensure both semantic meaning and preservation of indentation.

Operator Note: If you are displaying HTML tags inside a <pre> block, remember to escape special characters like < as &lt; to prevent the browser from rendering them.
HTML
<pre>
  <code>
    function hello() { return 'world'; }
  </code>
</pre>

Knowledge Check

Ready to test your understanding of 3. Text Elements?

Back