Congratulations! You made it! You learned all the principles to Responsive Typography! It’s important to set aside time to celebrate once in a while. Have a beer and give yourself a pat on the back! :)
Do it before, during or after this lesson. Whatever floats your boat. You can even send me an email to tell me you’ve completed the course! (Send away! I’ll be super happy to receive your email. 😉)
Back to the lesson. In this chapter, we’ll wrap up everything you’ve learned in Mastering Responsive Typography. They can be summarized into the six points below:
- The purpose of typography
- The relationship between font-size, leading and measure
- Use different font-sizes for different device widths
- Use relative units
- Use responsive Modular Scale
- Use responsive Vertical Rhythm
Let’s quickly run through all 6 points so you have an overview of how they all come together.
1. The purpose of typography
The purpose of typography is the first thing you learned in Mastering Responsive Typography. It is to help text achieve its purpose of communication. It means setting the right typeface and making sure text is readable.
This purpose guides all your typographic decisions. It gives you the confidence to stand your ground in your choices and prevents you from getting lost in the everyones’ opinion on the internet.
Next, you learned to typeset by choosing the right font-size, leading and measure.
2. The relationship between font-size, leading and measure
The key to all typography decisions is to choose a good size, a good leading and a good measure.
We can set their values in CSS via the following properties:
- size of text:
font-size - leading:
line-height - measure:
width
Remember, there’s no perfect values for any of the properties. What you should strive for is to make sure text remains readable at all times, which brings us to the next point.
3. Use larger font-sizes at larger devices
Your first challenge to make text readable is to increase font-sizes as devices gets larger since they’re held further away from a reader.
Doing so is quite simple in CSS:
html { font-size: 16px;}
@media (min-width: 1000px) { html { font-size: 18px; }}The problem with this CSS is that font-size of all browsers and devices aren’t set to 16px by default. If you set your font-size to 16px, you’re effectively overriding their efforts to produce text that’s optimized for readability. You’re also overriding your readers’ preferred font-size (if they set it).
To retain readability, we need to use relative units.
4. Use relative units
Relative units are units that derive their font-sizes from a parent element. When we use relative units, we respect device manufacturers for their expertise and users for their preference.
Since we’re talking about the html element, percentage units come to mind. The CSS is:
html { /* 16px */ font-size: 100%;}
@media (min-width: 62.5em) { /* 18px */ html { font-size: 112.5%; }}Of course, there are three other types of relative units you can use. They are em, rem and viewport units.
Now, since readability of the body text is settled, we can move on to determining the size of various other text elements on the page. The recommended approach is to use Modular Scale.
5. Use responsive Modular Scale
When determining the size of other text elements, we need to look their purpose once again.
Some elements, like the header and subheader, are there to grab a reader’s attention and to help organize the page into sections of content. Others, like meta information, can also be present to give readers more information about a subject. Of course, how you select the sizes for these elements will depend their purpose.
Since the olden days, typographers have used typography scales to help select sizes so we don’t pluck any numbers from thin air. On the web, we can’t use a traditional typography scale, so we rely on a modified version called a modular scale.
A Modular Scale serves two functions. It helps ensure there’s enough contrast between text sizes while at the same time employ repetition so your text flows in harmony with other elements on the page.
The best way to use Modular Scale is to use the Modular Scale Library. An implementation can look like this:
h1 { font-size: ms(3);
@media (min-width: 62.5em) { font-size: ms(4); }}Occasionally, you might need to change the leading for your headers because of the change in font-size if you want to retain maximum readability:
h1 { font-size: ms(3); line-height: 1.2; @media (min-width: 62.5em) { font-size: ms(4); line-height: 1.15; }}If you used a large ratio to construct your scale, you’ll run into a problem where you get gigantic font-sizes on a mobile device, which hinders readability.
The best way out is to create more flexibility in your scale by choosing one of the four methods:
- Use a smaller ratio
- Add a second base
- Add a second ratio
- Change the ratio at different breakpoints
Implementing the first three methods are simple. You just have to configure the $ms-base and $ms-ratio settings to your desired settings:
$ms-base: 1em 1.5em$ms-ratio: 1.333Implementing the final method is slight trickier. One way to do so is to use the respond-to mixin provided by the Modular Scale library to create your sizes.
$ms-range: 1.2 20em, 1.333 40em h1 { @include respond-to(font-size, 3);}The downsides to the respond-to mixin is that you can’t switch steps while simultaneously changing the modular scale ratios. I’ve personally found this functionality incredibly useful, so I added it to my responsive typography library, Typi. I’ll share more about Typi in the bonus section.
Once we’ve settled on the sizes of other elements, it’s time to zoom out and look at the design of the page. Here, we use a technique called Vertical Rhythm to ensure that our page flows harmoniously with the rest of our text.
6. Use (Responsive) Vertical Rhythm
Vertical Rhymth has it’s roots on the principle of repetition. Repetition brings familiarity and comfort, so the idea is to keep repeating a space so readers feel the familiarity and comfort without consciously knowing it.
If you have a large amount of text anywhere on your design, you already have a space that’s being repeated consistently — the body text’s line-height value. This line-height value forms the base of all other spaces of your design.
html { font-size: 100%; line-height: 1.4;}
h1 { margin-top: 2.8rem; /* 1.4 * 2 * 1rem */ margin-bottom: 1.4rem; // Other properties...}Unfortunately, it’s not so simple. The balance between font-size, leading and measure gets upset constantly on a responsive website. The font-size might change, the measure might change. So, the leading may also have to change to retain maximum readability.
The worse part is that there’s no easy way to change the leading and make sure Vertical Rhythm changes accordingly with the leading.
The best thing we can muster in CSS is to change every every element that’s derived from Vertical Rhythm whenever leading is changed, like this:
html { font-size: 100%; line-height: 1.4;
@media (min-width: 62.5em) { font-size: 112.5%; line-height: 1.45; }}
h1 { margin: 1.4rem;
@media (min-width: 62.5em) { margin: 1.45rem; }}
// ...It’s a lot of work :(
A simpler approach is to use CSS Variables so we remove the need to change other properties:
:root { --baseline: 1.4; @media (min-width: 62.5em) { --baseline: 1.45; }}
html { line-height: var(--baseline);}
h1 { margin: calc(var(--baseline) * 1rem);}Unfortunately, CSS Variables isn’t supported on Internet Explorer, so we need to progressively enhance it:
:root { --baseline: 1.4; @media (min-width: 62.5em) { --baseline: 1.45; }}
html { line-height: 1.4; line-height: var(--baseline);}
h1 { margin: 1.4rem; margin: calc(var(--baseline) * 1rem);}That’s all the six points! You’ll see something like this if we put all the code together:
:root { --baseline: 1.4; @media (min-width: 62.5em) { --baseline: 1.45; }}
html { font-size: 100%; line-height: 1.4; line-height: var(--baseline);
@media (min-width: 62.5em) { font-size: 112.5%; }}
h1 { font-size: ms(3); line-height: 1.2; margin: 1.4rem; margin: calc(var(--baseline) * 1rem);
@media (min-width) { font-size: ms(4); line-height: 1.3; }}
// Repeats the process for h2, h3, h4 and so forth...Wrapping Up
We summarized the ideas and principles of the course in 6 points. They are:
- The purpose of typography
- The relationship between font-size, leading and measure
- Use different font-sizes for different device widths
- Use relative units
- Use responsive Modular Scale
- Use responsive Vertical Rhythm
Always remember these 6 points as your work on your project. They’ll help you make decisions that have paralyzed many others.
Next up
You’ve gotten the basics to creating responsive typography for any web project now. In the following chapters, you’ll learn about optional things like how to use typi, how to talk to your designers, how to choose between rem and em, etc. They’ll give you further insight on how to responsive typography for a real world project.
Welcome! Unfortunately, you don’t have access to this lesson. To get access, please purchase the course or enroll in Magical Dev School.
Unlock this lesson