# Preformatted Text & Quotes

> Two special text blocks: <pre>, which keeps your spacing exactly, and <blockquote> with <cite>, which marks a real quotation and its source.

Subject: HTML | Lesson 7 of 42 | 5 min read
Interactive lesson: https://codewithanimation.in/html/preformatted-and-quotes
Previous: [Paragraphs & Breaks](https://codewithanimation.in/html/paragraphs-and-breaks.md) | Next: [Unordered & Ordered Lists](https://codewithanimation.in/html/lists.md)

## What it is

`<pre>` is preformatted text. Unlike a normal paragraph, it shows your content exactly as written, keeping every space, tab, and newline, and it renders in a monospace font by default. It is the natural home for code blocks and ASCII diagrams.

`<blockquote>` marks an extended quotation, a passage borrowed from somewhere else, and the browser usually indents it. Alongside it, the `<cite>` element marks the title of the work being quoted. Together they say not just how the text looks, but that it is a quote and where it came from.

## Why it matters

These two elements are where the rule from the last lesson flips. Normal HTML collapses your whitespace, but `<pre>` is the deliberate exception, which is exactly why every code block on the web sits inside one.

Quotations matter because meaning beats appearance. Anyone can indent text with CSS, but `<blockquote>` and `<cite>` tell browsers, search engines, and assistive technology that this passage is a genuine quotation from a named source, which plain indentation never communicates.

## How it works

Inside `<pre>`, whitespace is preserved instead of collapsed, so the text appears with the same line breaks and indentation you typed. The standard way to show code is to wrap a `<code>` element inside a `<pre>`. Because the content is still parsed as HTML, escape the syntax characters inside it: write `&lt;` for `<` and `&amp;` for `&`.

`<blockquote>` takes an optional `cite` attribute whose value is a URL pointing to the source. That attribute is machine-readable metadata only and is never shown on the page, so do not expect it to display.

To show a human-readable source, use the `<cite>` element, which marks the title of a creative work such as a book, article, or film and usually renders in italics. Two rules trip people up: `<cite>` is for the title of the work, not a person's name, and the visible attribution belongs outside the `<blockquote>`, in a following line or a `<figcaption>`, not inside the quoted text.

## Common mistake: Reaching for these tags just for their look

It is tempting to use `<pre>` only to get a monospace font, or `<blockquote>` only to indent something that is not a quote. That misuses their meaning: now assistive technology announces a quotation that is not one, or code styling on plain prose. Pick these elements for what the content is, and use CSS when you only want the visual effect.

## Tip: Know cite the attribute from cite the element

The `cite` attribute on `<blockquote>` is an invisible URL for machines. The `<cite>` element is visible text that names the work being quoted. When you want readers to see the source, write a `<cite>` with the work's title, placed just outside the blockquote, and reserve the `cite` attribute for the source link.

## Try it: Try it

On the left, the same indented code inside a normal element and inside `<pre>`, then a real quotation. On the right, watch `<pre>` keep every space while the plain version collapses, and see the blockquote with its `<cite>` source.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/html/preformatted-and-quotes

## Check yourself

### Question 1

How does <pre> treat the spaces, tabs, and newlines in its content?

- A. It preserves them exactly as written
- B. It collapses them into a single space, like normal HTML
- C. It removes all whitespace

Correct answer: A

`<pre>` preserves whitespace, so spaces, tabs, and newlines render as written, and it uses a monospace font. That is why code blocks live inside it.

- Why not B: That is normal paragraph behaviour. `<pre>` is the deliberate exception that keeps whitespace.
- Why not C: Nothing is removed; `<pre>` shows the text exactly as typed.

### Question 2

What does the cite attribute on <blockquote> do?

- A. Holds a URL pointing to the source; it is not shown on the page
- B. Displays the source as visible text under the quote
- C. Italicizes the quoted text

Correct answer: A

The `cite` attribute is a machine-readable URL for the quotation's source and is never rendered. To show the source to readers, use the `<cite>` element.

- Why not B: The attribute is metadata only. For visible attribution, use a `<cite>` element outside the quote.
- Why not C: It does not affect appearance at all; it is a machine-readable source URL.

### Question 3

What is the <cite> element for?

- A. Marking the title of a creative work, like a book or article
- B. Marking the name of the person who said it
- C. Wrapping any quoted text

Correct answer: A

`<cite>` marks the title of a cited work (a book, article, film, and so on) and usually renders italic. It is not for a person's name, and the visible attribution sits outside the blockquote.

- Why not B: A common mistake. `<cite>` is for the title of the work, not the author's name.
- Why not C: Quoted text goes in `<blockquote>` or `<q>`; `<cite>` names the source work.

## Remember this

- `<pre>` shows text exactly as written: it keeps spaces, tabs, and newlines and uses a monospace font.
- The `<pre><code>` pairing is the standard way to show a code block; escape `<` and `&` inside it.
- `<blockquote>` is a block-level quotation; its `cite` attribute is an invisible URL to the source.
- The `<cite>` element marks the title of a work (not a person), and visible attribution goes outside the blockquote.
