Responsive Typography
Jason Pamental
Dedication
Dedicated to my darling wife Ellen, without whom I would be rudderless; to Trevor and Phoebe for always keeping me humble; and to Tristan, my constant companion on our wooded walks at sunrise.
Foreword
Aaron Gustafson
Author, Adaptive Web Design
Back in my day, all we had was the font
element.
I fully realize that makes me sound like an old man, but Im not ready to chase young whippersnappers off my lawn quite yet. But the fact remains that when I taught myself how to build web pages back in the mid-90s, our design options were fairly limited. Heck, my first experience on the Web was on a text-based browser that provided me access to page upon glorious page of stark, blocky Courier. White text. Black background. 100% responsive.
When visual browsers finally hit the scene, ushering in images and the font
element, we web designers finally had the opportunity to move out of monospace. Ill leave it to Jason to delve into the history of typography on the Web, but the advent of visual browsers opened the floodgates for use (and abuse) of type online. It was the desktop publishing revolution all over again: a direct assault on the sensibilities of anyone with even the slightest understanding of typography.
Over the years, weve made a lot of mistakes with web type: fonts embedded in images. Fonts embedded in Flash. Fonts embedded in JavaScript. Many of those were attempts to bypass the gridlock created by browser makers, type foundries, and the W3C, who couldnt come to a consensus on how to balance a desire for more type options on the Web while ensuring typographers got paid for all of their hard work. While they bickered, we soldiered on, looking for more accessible and maintainable ways to use more typefaces.
And while we were busy tinkering with sIFR and Cufn, eagerly awaiting the day we could abandon those hacks and have real browser support for actual font formats, an army of little black rectangles had caught a whiff of the awesome content we were serving up to desktop browsers.
Like ants at a Sunday picnic, these little black rectangles initially appeared one or two at a time. They were easily ignored, a nuisance. Nothing to take too seriously. But before we knew what was happening, that trickle turned into a flood and those little rectangles were hungry. Instead of taking a crumb here and therewhich we tossed to them with a great sense of self-satisfactionthese ambitious ants were carrying off whole deli trays and the friggin New York Times .
These little black rectangles are, of course, the surge of handheld (or at least hand-holdable) devices that have been redefining our concept of the Web almost daily. They exhibit widely variable screen sizes: from about the size of a matchbook, to ones that are bigger than an extra large pizza. They sport a plethora of pixel densities, new interaction methods, unpredictable network connection speeds, and low-powered processors that cant possibly compete with traditional laptop and desktop CPUs (not to mention a handful of different operating systems and browsers). All of these factors affect howand even whetheryour typographic choices will make it to your customers, and its a lot to take in.
Thankfully, Jason has your back. The book youre now reading is invaluable: its chock-full of useful approaches, practical code samples, and advice for dealing with typography in the age of responsive web design.
By the time you finish this brief book, youll be ready to handle pretty much any device someone may throw at you. But hopefully they wont. Devices are hard. And expensive.
Preface
There are primarily three different but related audiences for this book:
- Traditional print-focused graphic designers
- Web designers
- Frontend developers
Traditional graphic designers need to know how to bring their knowledge of typography to the Web, how to find whats available, and how to use web fonts and understand technological limitations.
Web designers many of whom dont have a traditional design educationneed to understand the value of typography, what it can bring to their design, and what to watch out for when implementing web fonts.
Frontend developers are just as important: theyre often handed the job of incorporating web fonts into the site and are expected to do so successfully. Putting that first line of JavaScript or CSS in place is easy. Making sure the best methods for embedding are used, ensuring fallbacks are in place and tuned, and getting the best performance takes knowledge, time, and a bit of persistence.
What You Need to Know
Ive purposely kept the required technical knowledge modest in this book. In truth, you only need basic familiarity with HTML and CSS to make use of web fonts, though a smattering of JavaScript will do wonders to finesse the experience. All the sample code is complete and commented, so you may well be able to just take the sample code, work it into your own project, and modify it from there.
What You Dont Need to Know
All the code is kept fairly minimal, so while it will certainly make your life easier, you dont need to know anything about any CSS preprocessors like LESS or Sass. Likewise, the JavaScript is mostly cut-and-pasted from what the font services provide, to emulate what you are most likely to encounter when working with the font services on your own. It never hurts to know more, but Ive tried to ensure that even relative beginners can still get the most out of the examples provided.
About the Examples
The example files have been tested in a wide variety of both desktop and mobile browsers, on several different platforms and OSes. While nothing is certain in life or web development (aside from death and taxes), Ive done my best to be sure that the code provided will give consistent results wherever you use it. The text used is generally excerpts from Moby Dick by Herman Melville, a wonderful piece of literature that is also unencumbered by copyright. It makes for much more interesting samples than paragraphs of Lorem Ipsum, to say nothing of how much more naturally it flows within the page.
Organization of This Book
This book is organized in two parts..
Conventions Used in This Book
The following typographical conventions are used in this book:
Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. Constant width
Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords. Constant width bold
Shows commands or other text that should be typed literally by the user. Constant width italic
Shows text that should be replaced with user-supplied values or by values determined by context.
Tip
This element signifies a tip or suggestion.
Note
This element signifies a general note.
Warning
This element indicates a warning or caution.
Sample Code Repository
Ive started a repository on GitHub with the sample pages referenced in the book, in addition to the links provided (this repository will always have the most up-to-date code). You can find it here: http://bit.ly/rt-code-repo.
Using Code Examples
This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless youre reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from OReilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your products documentation does require permission.