Skip to content

Commit fd8670a

Browse files
authored
Merge pull request #938 from oddbird/utopia
Utopia
2 parents 3da4ba9 + 5ad99f4 commit fd8670a

6 files changed

Lines changed: 673 additions & 4 deletions

File tree

content/_includes/post.macros.njk

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ params:
3838
pagination=none,
3939
label='Posts'
4040
) %}
41+
{% set posts = posts | getPublic %}
4142
{%- if posts | length -%}
4243
{%- if posts | length > above -%}
4344
{%- for group in posts | eventSort | byYear -%}
@@ -87,7 +88,7 @@ params:
8788
banner_title=none,
8889
page_url=''
8990
) %}
90-
{%- set posts = collections[tag] -%}
91+
{%- set posts = collections[tag] | getPublic -%}
9192
{%- if posts | length -%}
9293
{%- set related = posts | pageYears | isPublicType | reverse | removePage(page_url) | onlyShow(limit) -%}
9394
{%- set title = banner_title or ['Posts about', tag] | join(' ') -%}
@@ -133,7 +134,7 @@ params:
133134
banner_title='Posts',
134135
page_url=''
135136
) %}
136-
{%- set posts = collections[type] -%}
137+
{%- set posts = collections[type] | getPublic -%}
137138
{%- if posts | length -%}
138139
{%- set recents = posts | isType(type) | pageYears | reverse | removePage(page_url) | onlyShow(limit) -%}
139140
{%- if recents | length -%}
@@ -834,7 +835,7 @@ params:
834835
banner_title='Featured Posts',
835836
class=none
836837
) %}
837-
{%- set featured = collections.posts | isHome(limit) -%}
838+
{%- set featured = collections.posts | getPublic | isHome(limit) -%}
838839
{%- if featured | length -%}
839840
{{ list(
840841
featured,

content/blog/2025/css-utopia.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
draft: true
3+
title: Utopian Typography in Modern CSS
4+
sub: Introducing the `progress()` function
5+
author: miriam
6+
date: 2025-06-18
7+
tags:
8+
- Article
9+
- CSS
10+
- Typography
11+
series: revisiting fluid typography
12+
permalink: false
13+
summary: |
14+
TBD
15+
---
16+
17+
I cited [Utopia.fyi](https://utopia.fyi)
18+
as my favorite tool for doing all the math
19+
to convert from 'actual' font and viewport sizes
20+
(pixel values) to the appropriate CSS `clamp()` output --
21+
which is not at all intuitive to do by hand.
22+
That's especially true
23+
if you rely on their advanced ability to scale
24+
not just the individual font sizes,
25+
but the relative ratio between steps.
26+
To do this, we input:
27+
28+
- Our desired (`px`) base font size on small screens
29+
- The (unitless) ratio between font sizes on a small screen
30+
- The minimum (`px`) viewport size
31+
at which fonts & scales should start growing
32+
- The maximum (`px`) viewport size
33+
where fonts and scales should stop growing
34+
- The desired (`px`) base size for large screens
35+
- The (unitless) ratio between sizes on large screens
36+
37+
We have several options for output,
38+
but the more readable CSS option looks like this:
39+
40+
```css
41+
:root {
42+
--step--2: clamp(0.7813rem, 0.7747rem + 0.0326vw, 0.8rem);
43+
--step--1: clamp(0.9375rem, 0.9158rem + 0.1087vw, 1rem);
44+
--step-0: clamp(1.125rem, 1.0815rem + 0.2174vw, 1.25rem);
45+
--step-1: clamp(1.35rem, 1.2761rem + 0.3696vw, 1.5625rem);
46+
--step-2: clamp(1.62rem, 1.5041rem + 0.5793vw, 1.9531rem);
47+
--step-3: clamp(1.944rem, 1.771rem + 0.8651vw, 2.4414rem);
48+
--step-4: clamp(2.3328rem, 2.0827rem + 1.2504vw, 3.0518rem);
49+
--step-5: clamp(2.7994rem, 2.4462rem + 1.7658vw, 3.8147rem);
50+
}
51+
```
52+
53+
- The `rem` values represent your desired base font size
54+
in relation to the common `16px` user-settings default
55+
- The `vw` values represent how much a font needs to scale
56+
relative to the viewport
57+
- The clamp min and max are direct representations
58+
of our desired small and large screen result
59+
- The internal calculation ensures
60+
that our growth is offset to the correct point,
61+
scaling from one value to the other
62+
over the proper range of screen sizes
63+
64+
I consider this the current state of the art,
65+
and I love using Utopia to get the output I need.
66+
With or without the specific tooling,
67+
this is a great CSS solution that has worked well for years.
68+
But I raised some concerns about the approach:
69+
70+
- **The resulting numbers feel magical**.
71+
I couldn't tell you how each one was calculated,
72+
and I wouldn't be able to update them manually in CSS.
73+
That's not a problem with Utopia,
74+
it's one of the reasons Utopia is so helpful.
75+
As a member of the CSS Working Group,
76+
I wonder if we can provide some of these tools
77+
in the language itself?
78+
- **I don't like the interaction
79+
between site and user font-sizes**.
80+
If I prefer a large font size for my design,
81+
and a visitor on my site
82+
prefers _the same large font size_,
83+
that's the font size we should use.
84+
We don't need to combine our preferences
85+
and render an _extra-large_ font size.
86+
- **I don't think in pixel values**
87+
when I'm defining fluid relationships.
88+
I think in relative units.
89+
Any CSS _pixel-to-em_ conversion math
90+
makes me squirm.
91+
92+
Many people,
93+
including [Richard Rutter](https://clagnut.com/blog/2441/),
94+
found my critique frustrating.
95+
It seems I wasn't very clear:
96+
97+
- That I think this solution is _pretty good_
98+
as a starting point,
99+
and is working from the right set of goals.
100+
I'm not opposed to fluid type,
101+
I want to see if we can improve how we achieve it in CSS.
102+
- That I love Utopia,
103+
and don't have any issues with it as a tool.
104+
As CSS has evolved since their first launch,
105+
Utopia's output has also changed to stay on the cutting edge.
106+
_Even if_ we can find even more modern CSS improvements,
107+
I imagine they'll remain the state of the art
108+
for visualizing the thought process to get there.
109+
- How I think about
110+
(or don't think about) pixels,
111+
and what it looks like to design
112+
without starting from a fixed unit.
113+
114+
Most importantly,
115+
I didn't have any real alternative to propose.
116+
My first stab at a 'solution'
117+
was pretty similar to Utopia's output,
118+
and extremely underwhelming.
119+
All I managed to do was remove some calculations,
120+
and replace them with _approximations_.
121+
122+
Those are valid critiques.
123+
I'm afraid I let a lot of things get mixed together
124+
in my original post,
125+
as I was just starting to put words to an idea.
126+
This time I want to break things apart,
127+
and look for real alternative approaches in CSS.

0 commit comments

Comments
 (0)