CSS talk: you should really know about the ch unit

This is an article about CSS and usability. The ch unit in CSS was a revelation for me, and I promise that if you don't know about it already, you're gonna love it.

I often joke that to learn about design is to doom yourself to be lightly annoyed by everything. After some repetition, you'll start to internalize some of the basic rules of industrial design, or print design, or fashion design, or mechanical design, or whatever it is that gets you excited. You'll start to find design quirks in the world which were once hidden to you. After all, every single thing in the built environment has been put there by someone who took their time to bring it to life. The downside, of course, is that you'll also start to see designs that downright suck. I find that it's helpful to think of it as finding opportunity for improvement.

Today's opportunity for improvement is brought to you by Wikipedia, which had me going cross-eyed as I read through an article in the early hours of this morning.

Screenshot of a wikipedia article on a wide monitor. Text spans fully from left to right, taking up the full width of available space.
A fullscreen desktop view of wikipedia on my 4k monitor.

What is a ch, and why you should c(h)are

It's simple, actually - ch is a CSS unit which represents the width of a character! If you're using a proportional font (where not all characters are the same width), 1ch is the width of the 0 character in the typeface you're using. This is particularly helpful for usability as it relates to reading long passages of text.

Line length and reading usability - err, readability

Limiting the line width for text in long passages is a great tool for making things more readable. Studies have shown that for optimal reading, text should be limited to somewhere around 60 characters per line. Think about it - this is why paperback books are generally smaller than an A4 page. This is why people love reading on their kindle. This is why Barnes and Noble sells Nooks like hotca — well, it's why the Nook is shaped like it is, at least.

In practice, what does this look like? Let's take that same wikipedia article and limit its paragraphs to 60 characters:

1
p {
2
max-width: 60ch;
3
}

Here's what it looks like:

The same wikipedia article with a limit set on p max-width for ch yields a page that is much easier to consume visually, and is more readable.
Column width adjusted using the CSS ch unit.

Okay, so that's not a fully-baked design update, but with a few tweaks we can make it a little nicer by bumping up the font size, and adjusting the layout of the right-hand column (side note: wikipedia uses float: right on that column, surprisingly!)

With a few additional layout tweaks, the page can be reflowed around the ch-limited paragraphs, making the entire article more coherent and easier to read.
Font size bumped up, and right-hand column adjusted to snap in place next to it. Much easier to read!

That's not bad at all! One of the nice things about using a character count for setting the width of that section is that it scales nicely for folks who use the browser's zoom functionality. You can also put your text passages inside of pixel-size-limited divs to make them work in responsive layouts at smaller sizes:

1
<style>
2
@media screen and (min-width: 800px) {
3
.blogpost {
4
max-width: 400px;
5
}
6
}
7
.blogpost p {
8
max-width: 60ch;
9
}
10
</style>
11
12
<div class="blogpost">
13
<p>
14
Fo ipsum dolor tellivizzle amet, my shizz adipiscing shizzle my nizzle
15
crocodizzle. Nullam sapien velizzle, shizznit volutpat, suscipit ass, away
16
vel, the bizzle. Dizzle fo shizzle tortizzle. Sizzle erizzle. Fusce izzle
17
dolizzle dapibus fizzle tempus dope. Maurizzle pellentesque hizzle et
18
turpis. Shiznit check out this fo shizzle. Pellentesque eleifend rhoncizzle
19
shiznit. In hac habitasse platea dictumst. Donec dapibizzle. Curabitizzle
20
tellus urna, pretizzle crackalackin, mattizzle ac, eleifend , nunc. Nizzle
21
suscipizzle. Integizzle rizzle you son of a bizzle sizzle mofo.
22
</p>
23
<p>
24
Dizzle ut dolizzle. Fusce magna crazy, dignissim sit amizzle, funky fresh
25
funky fresh, owned nizzle, tortor. Maecenas a nisi. Tellivizzle ghetto neque
26
izzle get down get down. Shut the shizzle up stuff. Cras aliquet tristique
27
turpizzle. Suspendisse gizzle ultricizzle dope. Sizzle get down get down
28
libero, fo shizzle mah nizzle fo rizzle, mah home g-dizzle interdum, posuere
29
mah nizzle, stuff izzle, crackalackin. Da bomb mofo tellizzle. Boom
30
shackalack aliquizzle gangster sizzle amet dolor. For sure dapibizzle sheezy
31
id mah nizzle. Shizznit mofo dolizzle shizzle my nizzle crocodizzle amizzle,
32
consectetuer adipiscing elit. Suspendisse pot purus, eleifend ,
33
ullamcorpizzle izzle, rizzle daahng dawg, elit. Nizzle porta rutrum nunc.
34
</p>
35
</div>

I dropped this stuff in a codepen if you'd like to play around with it. You'll see a green background when the media query activates.

Note: Cover Photo for this article is by Jelleke Vanooteghem on Unsplash. Thank you for your work!

Hero
CSS talk: you should really know about the ch unit

This is an article about CSS and usability. The ch unit in CSS was a revelation for me, and I promise that if you don't know about it already, you're gonna love it.

designuxcss
***
Mike Bifulco headshot

💌 Tiny Improvements Newsletter

Subscribe and join other builders

My weekly newsletter for product builders. It's a single, tiny idea to help you build better products.

    Once a week, straight from me to you. 😘 Unsubscribe anytime.


    Get in touch to → Sponsor Tiny Improvements