Fluid Typography (2024)

Photo by Ross Findon in Unsplash

You can access this article in Portuguese here
Você pode acessar este artigo em português aqui

A promise is a debt

A few days ago, I wrote about some typography tips. We discussed the importance of using the REM unit and how to make our fonts responsive using Media Queries. With that, you can already create impeccable web projects in terms of font size. But I promised to talk about making fonts responsive without using Media Queries, and a promise is a debt. So, here we go!

Fluid Typography (8)

The limits of Media Queries

When we adapt font sizes using media queries, our fonts remain the same size until they reach the breakpoint, and only then they change.

Open the CodePen below and adjust the screen width to see the sudden change in font size.


Open the CodePen in another tab.

Using the fluid typography technique, our font will always adjust to the screen size. For every pixel the screen increases, there will be an increment in font size.

"Caio, what kind of witchcraft is this? How is that possible?"

It's not witchcraft, but a powerful CSS function: clamp().

Getting to know 'clamp()'

With clamp(), we can define a minimum value, an ideal value, and a maximum value.

Let's say we want our font to be 16px on a screen width of 320px and 32px on a screen width of 1920px. Our clamp() would look something like this:

clamp(1rem, valor ideal, 2rem);/*You noticed that we're using REM, right?No PX for fonts, remember?*/

What about the ideal value? Well, since we want our font to adapt to the screen size, we'll use one of the viewport units, VW. 100vw is the size of the screen, and 1vw is 1% of the screen width. On a 320px screen, 100vw is 320px, and 1vw equals 3.2px.

Let's temporarily use the value of 5vw.

clamp(1rem, 5vw, 2rem)

With this, our font still has those minimum and maximum limits of 16px and 32px (based on the browser's default font), but with 5vw as the ideal value, it will always try to be 5vw in size.

Let's see some examples:

On a 300px screen: 5vw would be 15px. 15px is less than 16px - our minimum font size. In this case, the font would be 16px.

On a 320px screen: 5vw would be 16px. The font used would be 16px.

On a 500px screen: 5vw would be 25px. 25px is greater than 16px, and it's less than the maximum limit of 32px. So, the font used would be 25px.

On a 1000px screen: 5vw would be 50px. Since this value is greater than our limit, the font used would be 32px.

See this applied in the example below:

Open the CodePen in another tab.

Not everything is perfect

We have two problems here:

1) Our font is growing too quickly in this example. It reached our limit at a screen width of 640px, but we wanted it to vary fluidly up to 1920px. It becomes static for 1280px!

2) Using a font based solely on viewport units poses an accessibility problem. Try going back to the previous CodePen and zoom in on the screen. Users cannot zoom in on the font, which remains frozen since it's based on the screen size. You'll notice that the text in the center of the screen doesn't change in size, while the screen and font size counter in the upper-left corner increases.

Using VW + REM

A technique that helps with these two problems is to define the ideal value, the one in the middle of the clamp(), not just in VW, but as a sum of VW and REM.

Let's use the following values:

clamp(1rem, .8rem + 1vw, 2rem)

See in the example below that the font starts to grow exactly after 320px and stops just before 1920px!

Open the CodePen in another tab.

Fluid Typography (9)

"Caio, you're a genius! How did you come up with that value?"

I hate to disappoint you, dear reader, but I didn't do this calculation in my head! There is a formula to calculate this ideal value, and all the explanations for that will be in one of the articles I'll leave in the references. In this example and in my daily work, I use a tool that calculates it for me.

You can access this tool here.

The Fluid Type Calculator

Fluid Typography (10)

Here, we can define the minimum and maximum screen widths and the minimum and maximum font sizes — let's just ignore the Type Scale option for now.

The tool provides the clamp() values for you. Then, just add them to your code, and you're good to go.

Dealing with multiple font sizes simultaneously

"Caio, I've never worked on a project with just one font size!"

I know, I know. The example with only one font size was to make things simple. But there's no catch 22 here. Let's apply this logic to our first example, the one with fonts using Media Queries.

There, we had the following font model:

Level 1 -> 16px to 18px;

Level 2 -> 20px to 24px;

Level 3 -> 25px to 32px;

Level 4 -> 31px to 42px;

Now we just need to use our calculator for each of these ranges!

Previously, we had:

:root{ --fs-1: 1.125rem; --fs-2: 1.5rem; --fs-3: 2rem; --fs-4: 2.625rem}@media (max-width: 40em){ :root{ --fs-1: 1rem; --fs-2: 1.25rem; --fs-3: 1.5625rem; --fs-4: 1.9375rem }}

Now we end up with this:

:root{ --fs-1: clamp(1.00rem, calc(0.98rem + 0.13vw), 1.13rem);; --fs-2: clamp(1.25rem, calc(1.20rem + 0.25vw), 1.50rem); --fs-3: clamp(1.56rem, calc(1.48rem + 0.44vw), 2.00rem); --fs-4: clamp(1.95rem, calc(1.81rem + 0.71vw), 2.66rem)}

See the example below:

Open the CodePen in another tab.

Ok, what about the Type Scale Thing?

As developers, we often don't take part in the font size selection process. Designers usually lead that decision. "And how do they do that?", you might be wondering.

That's a science of its own. There are different systems: the 4-point grid, the 8-point grid, Google's Material Design, and many others. None of these systems can do without the trained eyes of design professionals: systems are not magic and often require adaptations.

One of these systems is modular scale typography. In this system, we start with a font size and increase or decrease it based on a multiplication factor. For example, let's say our smallest font is 10px, and the multiplication factor is 2. Our font system could have the following values: 10px, 20px, 40px, 80px, and so on. This example is exaggerated for didactic purposes, of course.

This methodology adds objectivity to font size selection and helps make our typography hierarchy more consistent.

The Type Scale field in our calculator helps generate fonts using this type of methodology. Let's say I have a project with 4 font levels (4 different sizes), and the smallest font should be 14px on mobile and 20px on monitors.

Fluid Typography (11)

Here, I'm applying a growth rate of 1.25 on 320px screens while applying a growth rate of 1.414 on 1900px screens. The result is as follows:

Fluid Typography (12)

Note that font sizes grow much faster on the 1900px screen because we used a higher rate. I invite you to read the excellent articles on modular typography scales that will be in the references of this article to better understand when to choose which rate for your scale. I also encourage you to generate and test different scales and compare the results. What happens when the scale rate is higher on larger screens than on smaller screens? What happens when the rate is the same? And when it's smaller?

Conclusion

We've learned how to apply the fluid typography technique using CSS. Fluid typography is an elegant solution that brings visual integrity to your project on various screens.

Always remember that accessibility is a priority. To ensure your website is accessible, always test it with a 200% zoom.

References

Kevin Powell - Simple solutions to responsive typography
https://www.youtube.com/watch?v=wARbgs5Fmuw

Modern Fluid Typography Using CSS Clamp
https://www.smashingmagazine.com/2022/01/modern-fluid-typography-css-clamp/

Generating font-size CSS Rules and Creating a Fluid Type Scale
https://moderncss.dev/generating-font-size-css-rules-and-creating-a-fluid-type-scale/

Responsive Type and Zoom
https://adrianroselli.com/2019/12/responsive-type-and-zoom.html

Resize text
https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-scale.html

Should I change the default HTML font-size to 62.5%?
https://fedmentor.dev/posts/rem-html-font-size-hack/

4-Point Grid System for more consistent interface design
https://medium.com/@aratidube12lns/4-point-grid-system-for-more-consistent-interface-design-efea81dea3f3

More Meaningful Typography
https://alistapart.com/article/more-meaningful-typography/

Um guia prático para criar um tipo de escala modular para suas interfaces
https://www.ux-republic.com/pt/guia-pr%C3%A1tico-para-criar-um-tipo-de-escala-modular-para-suas-interfaces/

Fluid Typography (2024)

FAQs

Fluid Typography? ›

Fluid typography is a responsive typography technique where the text scales automatically with the screen size. As the screen size increases, the typographic values such as font size, line height, and letter spacing increase. Similarly, the values decrease when the screen size gets smaller.

What is the difference between responsive typography and fluid typography? ›

Fluid typography is web text (or font size) that scales fluidly with the width of the browser. Typically, typography in responsive web design (or responsive typography) involves changing the font size at certain breakpoints via media queries.

What is fluid text? ›

The Fluid Text examines authorial, editorial, and cultural (i.e., adaptations, bowdlerizations) changes to texts and provides the first coherent theoretical, critical, and editorial approach to various versions of Melville's Typee to present protocols for fluid-text analysis and to demonstrate how book and computer ...

What is the line height for fluid type scale? ›

For ideal readability, aim for a line height that is about 130% to 150% the size of the font (so, 1.3 to 1.5 ). For optimal readability and accessibility, try 140% to 180% (that's 1.4 to 1.8 ).

Should I use VW or EM? ›

I usually choose EM because I want the size to be relative to the Heading's parent. But if you prefer to have the size be relative to the root (HTML) size, then choose REM instead. Or, you could set it to be relative to the viewport's width (VW) if that works better for your case.

When to use fluid typography? ›

Fluid typography is excellent for headings and display text. The giant text treatments that are as much a design element as they are copy, are the perfect use case for fluid typography. You want the size and visual impact of the text to match the size of the screen.

What are the three types of typography? ›

Typography Basics

There are five basic classifications of typefaces: serif, sans serif, script, monospaced, and display. As a general rule, serif and sans serif typefaces are used for either body copy or headlines (including titles, logos, etc.), while script and display typefaces are only used for headlines.

What is a fluid type font? ›

Fluid typography scales smoothly between the minimum and maximum value depending on the viewport width. It usually starts with a minimum value and it maintains the constant value until a specific screen width point at which it starts increasing.

What is a fluid style of writing? ›

The Fluid Writer maintains the context, allowing the author to explore multiple writing at a detailed level within a coherent structure, without losing the overview.

What is an example of fluid? ›

The substances which can flow easily are called fluids. all liquids and gases are fluids . example - water, oil, air etc.

What is fluid type size? ›

Preview your type scale
StepMinMax
md1.25rem1.58rem
lg1.56rem2.11rem
xl1.95rem2.81rem
xxl2.44rem3.75rem
3 more rows

What does line height 1.4 mean? ›

Each line becomes 1.4 lines in height, so it is 140% of it's original height based on your font-size. This is not the same as height:140%; since width and height % 's are based on the parent Element. line-height is not based on the parent Element, so line-height:140%; is the same as line-height:1.4; .

Why use REM instead of px? ›

Rems eliminate the need to write media queries to adjust font sizes and element dimensions for every possible device. Instead, proportions adapt naturally based on the user's default text size for their screen.

How many px is 1 rem? ›

1 rem = 16 pixels.

Why use em instead of px? ›

em is font-relative unit ,i.e., em is equal to the computed value of the font-size property of the element on which it is used. Use em when you specifically want the size of something to depend on the current font size. On the other hand, px or pixel, is an absolute unit, where 1 px = 1 / 9 6 = 1/96 =1/96th of an inch.

How is responsive design different from fluid design? ›

Unlike fluid design, responsive websites use breakpoints to rearrange or eliminate elements on a page, instead of simply resizing them. Therefore, a responsive layout might appear quite different on a desktop versus a tablet versus a smartphone. Take the responsive website for the clothing brand Kotn, for example.

What is responsive typography? ›

Understanding Responsive Typography: Responsive typography involves creating an optimal reading experience for users on different devices by adjusting font sizes, line heights, and spacing.

What is the difference between responsive and nonresponsive design? ›

Responsive sites display differently to accommodate various screen sizes, reflowing to fit nicely onto your tablet or mobile phone. Unresponsive sites display on other screen sizes, but they do not adjust at the code-level for those screen sizes.

What is the difference between responsive and adaptive design? ›

Where responsive design relies on changing the design pattern to fit the real estate available to it, adaptive design has multiple fixed layout sizes. When the site detects the available space, it selects the layout most appropriate for the screen.

Top Articles
Latest Posts
Article information

Author: Terrell Hackett

Last Updated:

Views: 6002

Rating: 4.1 / 5 (52 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Terrell Hackett

Birthday: 1992-03-17

Address: Suite 453 459 Gibson Squares, East Adriane, AK 71925-5692

Phone: +21811810803470

Job: Chief Representative

Hobby: Board games, Rock climbing, Ghost hunting, Origami, Kabaddi, Mushroom hunting, Gaming

Introduction: My name is Terrell Hackett, I am a gleaming, brainy, courageous, helpful, healthy, cooperative, graceful person who loves writing and wants to share my knowledge and understanding with you.