Loading...

HTML essentialsContent

Quotes, code & preformatted text

4 min lesson

Next
  • Some content needs special tags: quotations, code samples and text where spaces matter.
  • <blockquote> marks a long quotation as a block; <q> marks a short inline quotation.
  • <code> marks a piece of code inline, and <pre> keeps spaces and line breaks exactly as typed.
  • Combine <pre> and <code> for multi-line code blocks, which is the usual pattern.
  • This builds on Inline text formatting: you now have special-purpose tags for special content.
  • The example shows a short quote, a long quote, and a code block; you will see indented quotes and monospaced code.
  • Next, Lists (ordered, unordered, description) adds structured groups of items.
Keep in mind
  • Use blockquote for long quotes and q for short ones inside a sentence.
  • Use pre when spacing and line breaks must be preserved.
  • Pair pre with code for multi-line code samples.
  • Do not use pre to fake layout; use CSS for layout.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Quotes & code</title>
</head>
<body>
  <!-- A short inline quote -->
  <p>She said <q>keep it simple</q> and smiled.</p>
  <!-- A long quote as its own block -->
  <blockquote>
    Simplicity is the soul of efficiency.
  </blockquote>
  <!-- pre keeps spacing; code marks it as code -->
  <pre><code>int main(void) {
    return 0;
}</code></pre>
</body>
</html>

What happens: A paragraph reading "She said “keep it simple” and smiled.", an indented block quote reading "Simplicity is the soul of efficiency.", and a code block showing: int main(void) { return 0; }

Breaking it down

q

<q>keep it simple</q>

Marks a short quote inside a sentence. Browsers add quotation marks around it automatically.

blockquote

<blockquote>...</blockquote>

Marks a longer quote as a block. Browsers indent it, so it stands apart from the main text.

pre

<pre>...</pre>

Keeps all spaces and line breaks exactly as typed. Use it when formatting carries meaning.

code

<code>return 0;</code>

Marks text as code. Browsers show it in a monospaced font so characters line up.

Quote & code tags

TagUse forDisplay
qShort inline quoteAdds quotation marks
blockquoteLong block quoteIndented block
codeInline codeMonospaced font
preText with exact spacingPreserves spaces and lines

A helpful analogy

pre is like a photograph of a page: spaces and line breaks stay exactly where they were. A normal paragraph is like retyping the page, where the browser tidies the spacing.

Nesting rules

  • 1.Put <code> inside <pre> for multi-line code, not the other way around.
  • 2.Keep blockquote as a block: do not put it inside a paragraph.

Common mistakes

Using pre to align normal text

Avoid

<pre>Name: Alice</pre>

Use instead

<p>Name: Alice</p> plus CSS for layout

pre forces a monospaced font and fixed spacing, which breaks on small screens. Use CSS for layout instead.

Putting blockquote inside a p

Avoid

<p>He said <blockquote>hi</blockquote></p>

Use instead

<p>He said <q>hi</q></p>

blockquote is a block and cannot live inside a paragraph. Use q for short quotes inside text.

Quick tips

  • •View the source of a code tutorial site to see how they wrap pre and code around samples.
  • •Use <pre><code> in every code sample so indentation is preserved.
Previous
Next