As I said in one of my talks at the Dayton Web Developers meeting:
"With a solid typographic scale you might even get away with not using a single image on your website."
The power of typography has got to be one of the most underappreciated assets in web design. Admittedly, we are seeing more and more designs where typography has been strongly considered, playing a major role in creating the intended atmosphere of a website or app.
In this chapter, our focus is going to be on a few aspects, tips, and tricks about the things we need to consider for RWD from a typography stand point.
We're going to talk about:
FitText.js for fluid-size headings.FlowType.js to improve legibility.It is difficult to decide whether to use pixels, ems, or rems for typography. It's a matter of style. Some web designers/developers still use pixels as their unit to declare font sizes. It's just a lot easier to wrap our heads around the sizes.
The issues with setting font sizes in pixels were basically on legacy IEs, where, if the user wanted to zoom in on the page for whatever reason, the text would stay fixed at the pixel size it was given.
Now, that's a thing of the past as far as modern browsers are concerned. When you zoom in any modern browser, if it's zoomed in enough, it will trigger the media queries, hence showing the mobile version of the site.
Another problem with pixel-based font sizing is that it's hard to scale and maintain. What this basically means is that we'd have to declare the font sizes of many more elements in every media query, over and over and over.
On the other hand, we have relative units, ems and rems, which are pretty much the recommended way of setting our font sizes.
However, the problem with ems is that we have to keep track (mentally, in CSS/HTML comments, or in a text file somewhere) of the sizes of the parent containers, which can easily turn into a font management nightmare. A font size in ems depends on the font size of its parent container. So if we have different levels of nested containers, things could get ugly really fast because keeping track of the parent container's font sizes is not easy.
But then rems came along. Rem means root em. The root is the <html> element.
Rems bring pretty much the best of both worlds: we can declare font sizes in rems with the same mental model that we declare pixels, but with the benefit of using relative units like ems. The only problem with using rems is that legacy browsers don't support this unit, so a pixel-based, font size fallback value needs to be accounted for. This is where a short Sass mixin comes and saves the day.
But let's start with the core strategy of this chapter before trying any Sass tricks.