Pull Quotes with HTML5 and CSS

A pull quote is a typographical technique in which an excerpt or quote from an article is duplicated within the article using a different formatting style so that it jumps out at the reader.

Blatantly copying the excerpt of the pull quote into it’s own element is not the way to go. A pull quote is a purely visual technique, and therefore should not change the structure of the body. Next to that, a structural representation of the excerpt would be seen twice by people using feed readers or services like Instapaper, as well as be re-read for people who use screen readers. So how can we best author this into our mark-up?

Our good friend, the data attribute

HTML5 introduced the ability for authors to create custom non-visible data-attributes. These attributes can contain data that will not affect layout or presentation.

Custom data attributes are intended to store custom data private to the page or application, for which there are no more appropriate attributes or elements.

By adding a data-pullquote attribute to an element, we attach the text of the pull quote to it, yet do not add visible content.

Displaying the pull quote

Using the CSS content property with a value of attr(data-pullquote), we can show the pull quote with either the :before or :after pseudo-class of the aforementioned block level element. Currently, I prefer using the :before pseudo-class, as I believe this allows for more consistent styling with floats. A more extensive look at the CSS would be as follows:

.has-pullquote:before {
	/* Reset metrics. */
	padding: 0;
	border: none;
	
	/* Content */
	content: attr(data-pullquote);
	
	/* Pull out to the right, modular scale based margins. */
	float: right;
	width: 320px;
	margin: 12px -140px 24px 36px;
	
	/* Baseline correction */
	position: relative;
	top: 5px;
	
	/* Typography (30px line-height equals 25% incremental leading) */
	font-size: 23px;
	line-height: 30px;
}

In the implementation on this blog, I’ve aligned the pull quote right of the content by default. With a secondary classname, the pull quote can be aligned in different standardized fashions.

.pullquote-left:before {
	float: left;
	margin: 12px 31px 24px -102px;
	
	width: 251px;
}

Next to that, what you might have noticed in the code: the pull quotes on here are based on a vertical rhythm with an incremental ratio of 5:4. Mark Boulton has written a great article on incremental leading.

Varying and lining up the pull quote

Different articles can have a need for different pull quotes. By creating a few standardized classnames for these different instances, we can make it easy on ourselves during the authoring process. Here are a few examples regarding different typefaces – including the detail of different vertical offsets per typeface, to keep them aligned to the typographic vertical rhythm.

.pullquote-adelle:before {
	font-family: "adelle-1", "adelle-2";
	font-weight: 100;
	
	top: 10px !important;
}

.pullquote-helvetica:before {
	font-family: "Helvetica Neue", Arial, sans-serif;
	font-weight: bold;
	
	top: 7px !important;
}

.pullquote-facit:before {
	font-family: "facitweb-1", "facitweb-2", Helvetica, Arial, sans-serif;
	font-weight: bold;
	
	top: 7px !important;
}

These pull quotes are supported by every modern browser down to IE8.

This article is also available in Bulgarian.

Update: Aaron Gustafson built a nice jQuery addition to this that automatically puts the quoted text in the data attribute of the paragraph it is in, removing the need to enter it twice. Mind you, this removes the flexibility to add the pull quote to a different paragraph.