You're writing an article and want to include a sentence from a book you like. Readers need to know that the sentence is a quote: someone else's words, not yours. HTML has three special tags for quotes:
<blockquote>for a long quote,<cite>for the title of the work you quote from, such as a book,<q>for a short quote in the middle of a sentence.
Long quotes with <blockquote>
Here's a sentence from the preface of a programming book:
<blockquote cite="https://example.com/sicp/preface">
<p>Programs must be written for people to read, and only incidentally for machines to execute.</p>
</blockquote>
<cite>Structure and Interpretation of Computer Programs</cite>
<blockquote>opens a long quote, and</blockquote>closes it.cite="https://example.com/sicp/preface"is an attribute that holds the web address of the quote's source. Write it inside the opening tag, before the>.<p>wraps the quoted sentence, inside the<blockquote>.- The
<cite>after</blockquote>holds the book's title.
The quoted sentence shows on a line of its own, slightly indented (with some space on its left and right). <blockquote> is a block element, so it always starts on a new line. Below the quote, the book title shows in italics. The address in the cite attribute doesn't show anywhere.
The cite attribute and the <cite> tag are different
The example above uses the name cite twice, for two different jobs:
- The attribute
cite="address"goes inside the opening tag of a<blockquote>or a<q>. It holds the web address of the quote's source. It doesn't show on the page, but it is still in the code. So other programs, like search engines, can read it. - The tag
<cite>Title</cite>is an element of its own, with an opening and a closing tag. It holds the title of a work, such as a book, an article or a film. The title shows on the page, in italics.
So don't write the address in <cite>, and don't write the title in the cite attribute. An author's name isn't the title of a work either: write the name as plain text, outside <cite>. To keep the quote and its source together as one unit, wrap the <blockquote> and its source in a <figure> tag. Write the source in a <figcaption> tag (a caption), after </blockquote>: <figcaption>Abelson and Sussman, <cite>Structure and Interpretation of Computer Programs</cite></figcaption>.
Short quotes with <q>
Here is a short quote inside a sentence:
<p>My lecturer says <q>code is written for people to read</q>, so keep your code as tidy as you can.</p>
<q> is an inline element, so the quote stays inside the sentence and doesn't move to a new line. The browser adds the quote marks at the start and end of the quote.
The page shows one whole sentence, with "code is written for people to read" already inside quote marks. Because the browser adds them, don't type " inside <q> as well.
⚠️ Which is the quote, which is the title?
- A second
<blockquote>for the title. A title isn't a quote. Use<cite>. - Typing quote marks inside
<q>. The quote marks show twice. <blockquote>just to indent. If the text isn't a quote, don't use<blockquote>. Positioning is the job of CSS, which you'll learn after HTML.- Splitting a quote of several paragraphs. Don't make one
<blockquote>per paragraph. All the<p>s of one quote go in one<blockquote>.
TL;DR: <blockquote> is for a long quote, shown on a line of its own and slightly indented. <q> is for a short quote inside a sentence, and the browser adds its quote marks. The web address of the quote's source goes in the cite="..." attribute, in the opening tag of <blockquote> or <q>, and doesn't show. The title of the work you quote from (such as a book) goes in a <cite> tag, and shows in italics.
⚡ A long quote
Write:
<blockquote cite="https://example.com/sicp/preface">
<p>Programs must be written for people to read, and only incidentally for machines to execute.</p>
</blockquote>
<cite>Structure and Interpretation of Computer Programs</cite>
Meaning: <blockquote> marks a long quote. It is a block: the quote shows on a line of its own, slightly indented. The <cite> after it holds the title of the book you quote from, shown in italics.
⚡ Two different cites
Guess first: where does the address in cite="..." show?
Nowhere. The address stays in the code, so other programs like search engines can read it.
Meaning: The cite="..." attribute holds the web address of the quote's source. The <cite> tag holds the title of a work, such as a book. An author's name isn't a title, so it goes outside <cite>.
⚡ A short quote inside a sentence
Write:
<p>My lecturer says <q>code is written for people to read</q>, so keep your code as tidy as you can.</p>
Guess first: do you type the quote marks?
No. The browser adds them. If you type them too, the quote marks show twice.
Meaning: <q> is inline, so the short quote stays inside the sentence. <blockquote> is for a long quote that shows on a line of its own.