Quotations, Code and Preformatted Text
blockquote, q, cite, abbr, code, pre, kbd and samp. Eight elements that make quoted material and technical text mean what it says.
-
HTML Basics
- What is HTML: The Structure Layer of Every Web Page
- HTML Document Structure: DOCTYPE, html, head and body
- Elements, Tags and Attributes: The Vocabulary of HTML
- HTML Comments: Notes That Ship With Your Code
- Block Level and Inline Elements
- Writing and Running Your First HTML Page
- How a Browser Turns Markup Into a Page
- Text and Formatting
- Links and Navigation
- Images and Media
- Lists
- Tables
-
Forms
- Form Structure: form, action and method
- Input Types: Text, Email, Number, Date and the Rest
- Labels: The Most Important Element in a Form
- Checkboxes, Radio Buttons and Grouping
- select, option, optgroup and datalist
- textarea, File Uploads and Hidden Fields
- Buttons: submit, reset and button
- Built In Form Validation
- GET or POST: What Happens When a Form Is Submitted
- Semantic HTML
- HTML5 Features
- Head and Metadata
- HTML with CSS
- HTML with JavaScript
- Accessibility
-
HTML SEO
- How Google Works: Crawling, Indexing and Ranking
- SEO Friendly HTML Structure
- Titles and Descriptions That Earn Clicks
- Headings and Content Structure for Search
- Internal Linking and Anchor Text
- robots.txt and XML Sitemaps
- Canonical URLs and Duplicate Content
- Structured Data and JSON-LD
- Image SEO
- Core Web Vitals and Mobile Friendliness
- DevTools and Debugging
- Editor Productivity
- HTML Best Practices
- HTML Projects
- Advanced Projects
- Practice and Exams
Concept
Two families of elements that beginners often replace with a styled div: those that mark quoted material, and those that mark technical text. Both add meaning a stylesheet cannot, and both are trivial to use.
Quotations
blockquote
An extended quotation set off as its own block. The optional cite attribute holds a URL pointing at the source.
<figure>
<blockquote cite="https://example.org/reports/2026-transport">
<p>Bus ridership recovered faster than any other mode, and did so
without any increase in fares.</p>
</blockquote>
<figcaption>
District Transport Review, <cite>Annual Report 2026</cite>
</figcaption>
</figure>The URL in the cite attribute is not displayed by any browser, so a visible attribution needs its own markup. Wrapping the quote in a figure with a figcaption is the standard way to attach one, because the attribution is not itself part of the quotation.
q
A short inline quotation. The browser inserts the quotation marks itself, choosing the correct pair for the language.
<p>The notice said <q>services resume at six</q>, which turned out to be optimistic.</p>Do not type quotation marks around a q. You will get two sets.
cite
The title of a work: a book, a film, a report, a paper, a song, a piece of software. Not the name of a person - that is a common misreading of the element.
<p>The argument is developed at length in <cite>The Fare Trap</cite>.</p>abbr
An abbreviation or acronym, with the expansion in the title attribute.
<p>The <abbr title="Municipal Transport Authority">MTA</abbr> publishes figures yearly.</p>Because title is not reachable by keyboard or touch, the expansion should also appear in the text on first use. Write it out in full the first time and abbreviate afterwards.
Technical text
code
A fragment of computer code: a function name, a file name, a property, a command.
<p>Set the <code>loading</code> attribute to <code>lazy</code>.</p>pre
Preformatted text. This is the one element where whitespace is preserved exactly: every space, every tab, every newline. It is the exception to the collapsing rule.
For a code block, nest code inside pre. The pre preserves the layout; the code says it is code.
<pre><code>function total(items) {
return items.reduce((sum, n) => sum + n, 0);
}</code></pre>Note two details. The opening <code> sits immediately after <pre> with no newline, because a newline there becomes a blank first line. And every < and & inside the block must be escaped as < and & - otherwise the browser reads them as markup and your example disappears into the DOM.
kbd and samp
kbd is input the user types; samp is output a program produced.
<p>Press <kbd>Ctrl</kbd> + <kbd>S</kbd> to save.</p>
<p>The build printed <samp>2 files changed</samp> and exited.</p>Escaping: the rule that catches everyone
Three characters cannot appear literally in HTML text. Showing markup on a page is impossible without them.
| Character | Entity | Why |
|---|---|---|
< | < | Starts a tag |
> | > | Ends a tag |
& | & | Starts an entity |
" | " | Only needed inside an attribute value |
Escape the ampersand first when doing this by hand, or you will double escape everything that follows.
Important rules
blockquoteis block level and should contain block content such as paragraphs;q,cite,abbr,code,kbdandsampare inline.- The
citeattribute is never displayed. Theciteelement is displayed. They are unrelated things with the same name. preis the only common element that preserves whitespace.- The attribution to a quotation belongs outside the
blockquote, because the attribution is not part of what was said. - Do not add your own quotation marks around
q.
Common mistakes
- Using
blockquoteto indent text that is not a quotation. Indentation ismargin. - Putting the attribution inside the
blockquote, which makes it look as if the source quoted its own name. - Forgetting to escape
<in a code sample and losing the whole example. - Using
citefor the name of the person who said something. - Relying only on
abbr titlefor an expansion no touch user will ever see. - Starting a
preblock with a newline and shipping a stray blank line.
Best practices
- Pair
prewithcodefor every code block, and add a language hint such asclass="language-js"for highlighters. - Give long code blocks
overflow-x: autoso they scroll inside their own box instead of stretching the page on a phone. - Expand an abbreviation in the text on first use, then use
abbrfor later occurrences. - Wrap a quotation and its attribution in a
figureso they stay associated. - Always fill in the
citeattribute when the source has a URL. It costs nothing and machines can read it.
Practice
- Mark up a quotation of two paragraphs with a visible attribution and a source URL, without putting the attribution inside the quote.
- Display
<a href="/x">Link</a>on a page as visible text. Which characters did you have to escape? - Write instructions containing a keyboard shortcut, a file name and a line of program output, using the correct element for each.
- Explain the difference between the
citeelement and theciteattribute in one sentence.