Easy Fluid Typography
Tags: typography, css, webdesign, webdev
Published: 2021-05-18 02:06:54

---
title: Easy Fluid Typography
published: true
date: 2021-05-18 01:36:27 UTC
tags: Typography,CSS,WebDesign,WebDev
canonical_url: https://ryanfeigenbaum.com/fluid-typography/
---

 ![Easy Fluid Typography](https://ryanfeigenbaum.com/content/images/2021/05/fluid.jpg)

💡 [This post updates my earlier article, "Easy Responsive Typography"](https://ryanfeigenbaum.com/easy-responsive-typography/)

This tutorial shows you how to implement fluid typography easily on your website and provides [an interactive calculator](https://royalfig.github.io/fluid-typography-calculator/) to determine the typography scale that works best for you!

## What is Fluid Typography?

Fluid typography is text that scales in size in proportion to the user's viewport. Although it might be counterintuitive, font size should decrease as the screen becomes smaller and vice versa.

### Fluid Typography ≠ Responsive Typography

While fluid and responsive typography achieve the same ends—increasing and decreasing font size in proportion to screen size (viewport)—their implementation is different. Responsive typography works by changing font size via media queries.

```css
html {
    font-size: 1rem;
}

@media (min-width: 640px) {
    html {
        font-size: 1.125rem;
    }
}

@media (min-width: 1024px) {
    html {
        font-size: 1.25rem
    }
}
```

But responsive typography is limited by not being _fluid_; i.e., the same font size will apply for a large swath of viewports. As the example shows, the font size will not change between 640 and 1023px.

Nevertheless, there's nothing wrong with using responsive typography. It has the widest browser support and is the easiest method to implement—at least until now!

## The Clamp Champ 👑

With [support in all major modern browsers](https://caniuse.com/mdn-css_types_clamp), the CSS function `clamp()` is the perfect tool for easily implementing fluid typography. Like the tool, this function holds a value (or range of values) in place, ensuring they don't exceed upper and lower bounds. It can be applied to any CSS property that accepts a numeric value.

> `clamp(min, preferred value, max)`

The syntax for the clamp function is simple: `clamp(min, preferred value, max)`. The min and max refer to the upper and lower bounds. For example, if you don't want your font size to go below `16px` or exceed `20px`, you would use these values as your min and max.

That leaves the preferred value: as long as it is in between the min and max, it will be the selected value. This is powerful because the preferred value can be a dynamic or mathematical expression. For example, in `clamp(16px, 2vw, 20px)`, as long as 2vw (2% of the viewport width) is greater than 16px and less than 20px, it will be the the CSS property's computed value. Where it is less or greater, the value will default to `16px` and `20px`, respectively.

## Calculator

Better minds than mine have worked out formulae for calculating your preferred value, which determine the rate at which your font size scales. To make the process even easier, I've built a [fluid typography calculator](https://royalfig.github.io/fluid-typography-calculator/) that not only calculates the mathematical expression for the preferred value, but also allows you to visualize the scale through a simulated viewport. It also produces CSS you can easily copy and paste into your code.

Here's the fluid typographic scale for the website on which you're reading this article:

```css
html {
    font-size: 1rem;
	font-size: clamp(1rem, 0.95rem + 0.25vw, 1.25rem);
}
```

The calculator has some other benefits like automatically converting from `px` to `rem` and vice versa (which is necessary to maximize accessibility), as well as providing a dead simple fallback for cases where `clamp` isn't supported. (For a more advanced fallback, see Daniel Yuschick's article, "[Fluid Typography is My New Favorite Thing](https://dev.to/yuschick/fluid-typography-with-css-clamp-is-my-new-favorite-thing-4lg3).")

[Check out the calculator 🧮](https://royalfig.github.io/fluid-typography-calculator/)

## Sources & Resources
[Modern Fluid Typography](https://chriskirknielsen.com/blog/modern-fluid-typography-with-clamp/)

[Fluid Typography is My New Favorite Thing](https://dev.to/yuschick/fluid-typography-with-css-clamp-is-my-new-favorite-thing-4lg3)