Fluid typography examples

A few months ago I published a fluid type technique that doesn’t require any JavaScript. Even though I consider it experimental the technique works well enough as a progressive enhancement and it generated a lot of interest, comments a…

A few months ago I published a fluid type technique that doesn’t require any JavaScript. Even though I consider it experimental the technique works well enough as a progressive enhancement and it generated a lot of interest, comments and suggestions. So I thought I’d put together a bunch of examples and address some comments.

Fluid type with pixels

This is a simplified version of my original example. The minimum font size is 14px and the maximum is 22px. I’ve removed a redundant media query and reduced the complexity of the calc() equation.

.fluid-type {
font-size: 14px;
}

@media screen and (min-width: 320px) {
.fluid-type {
font-size: calc(14px + 8 * ((100vw - 320px) / 960));
}
}

@media screen and (min-width: 1280px) {
.fluid-type {
font-size: 22px;
}
}

Example

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo.

Fluid type with Rem units

This example should have the same result as the one above when the base font size is 16px (default).

It shows that the technique works with any length unit, as long as you can use it in a media query. It also addresses comments regarding how my initial example will override user preferences for the default font size.

The only catch is that all unit types must be the same for the calc() equation to work. That’s a shame because we often use different unit types for breakpoints in media queries than we do for font-size.

.fluid-type {
font-size: 0.875rem;
}

@media screen and (min-width: 20rem) {
.fluid-type {
font-size: calc(0.875rem + 0.5 * ((100vw - 20rem) / 60));
}
}

@media screen and (min-width: 80rem) {
.fluid-type {
font-size: 1.375rem;
}
}

Example

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo.

Reverse fluid type

In this example the text gets smaller as the viewport gets larger. This might have novel uses or it might not.

.fluid-type {
font-size: 22px;
}

@media screen and (min-width: 320px) {
.fluid-type {
font-size: calc(22px + -8 * ((100vw - 320px) / 960));
}
}

@media screen and (min-width: 1280px) {
.fluid-type {
font-size: 14px;
}
}

Example

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo.

Fluid line-height (Molten leading)

In this example the line-height is fluid. This is a pure CSS implementation of Wilto’s Molten leading technique.

.molten-leading {
line-height: 1.2em;
}

@media screen and (min-width: 20em) {
.molten-leading {
line-height: calc(1.2em + 0.6 * ((100vw - 20em) / 60));
}
}

@media screen and (min-width: 80em) {
.molten-leading {
line-height: 1.8em;
}
}

Example

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo.

Fluid box

This example shows how the technique can be applied to more than just font sizes, in this case width.

.fluid-box {
width: 200px;
}

@media screen and (min-width: 320px) {
.fluid-box {
width: calc(200px + 300 * ((100vw - 320px) / 960));
}
}

@media screen and (min-width: 1280px) {
.fluid-box {
width: 500px;
}
}

Example

The width of this box will scale and at a different rate to the viewport.

Fluid type in Sass

Indrek Paas developed a Sass mixin to help make fluid type using this technique easier. You can find the latest fluid type Sass mixin here.

Update: I now recommend using this mixin

I use a slightly modified version to generate the examples on this page.

Example:

.fluid-type {
@include fluid-type(320px, 1280px, 14px, 18px);
}

Fluid type in Less

If Less is how you roll I’ve got you covered with a Less mixin.

Fluid type in PostCSS

Rucksack is a postCSS module that makes use of this technique for fluid typography.

I have a collection of other examples on CodePen. Let me know if you have one you’d like me to share.


Print Share Comment Cite Upload Translate
APA
Mike | Sciencx (2024-03-29T13:49:37+00:00) » Fluid typography examples. Retrieved from https://www.scien.cx/2015/07/15/fluid-typography-examples/.
MLA
" » Fluid typography examples." Mike | Sciencx - Wednesday July 15, 2015, https://www.scien.cx/2015/07/15/fluid-typography-examples/
HARVARD
Mike | Sciencx Wednesday July 15, 2015 » Fluid typography examples., viewed 2024-03-29T13:49:37+00:00,<https://www.scien.cx/2015/07/15/fluid-typography-examples/>
VANCOUVER
Mike | Sciencx - » Fluid typography examples. [Internet]. [Accessed 2024-03-29T13:49:37+00:00]. Available from: https://www.scien.cx/2015/07/15/fluid-typography-examples/
CHICAGO
" » Fluid typography examples." Mike | Sciencx - Accessed 2024-03-29T13:49:37+00:00. https://www.scien.cx/2015/07/15/fluid-typography-examples/
IEEE
" » Fluid typography examples." Mike | Sciencx [Online]. Available: https://www.scien.cx/2015/07/15/fluid-typography-examples/. [Accessed: 2024-03-29T13:49:37+00:00]
rf:citation
» Fluid typography examples | Mike | Sciencx | https://www.scien.cx/2015/07/15/fluid-typography-examples/ | 2024-03-29T13:49:37+00:00
https://github.com/addpipe/simple-recorderjs-demo