Passer au contenu principal
Bluvy Tube
Appuyez sur Échap pour quitter le plein écran
Volume m
/
i
Mode Cinéma t
f
/
Playing around with an idea: responsive code. The build script creates up to 5 versions of each code sample using Prettier, and a container query displays the right one. Brotli means the filesize overhead is very small. Live demo: jakearchibald.com/2026/css-cus...

Raccourcis clavier

Espace K
Lecture / pause
← →
Reculer / avancer de 5 s
J L
Reculer / avancer de 10 s
0–9
Aller à 0 %–90 % de la vidéo
Home End
Début / fin
, .
Image précédente / suivante (en pause)
< >
Ralentir / accélérer
↑ ↓
Volume
M
Couper / rétablir le son
C
Sous-titres
F
Plein écran
I
Image dans l’image
T
Mode cinéma
?
Afficher cette aide

Playing around with an idea: responsive code. The build script creates up to 5 versions of each code sample using Prettier, and a container query displays the right one. Brotli means the filesize overhead is very small. Live demo: jakearchibald.com/2026/css-cus...

0 vue Publié le 04/09/2026 13:23 0:09
Playing around with an idea: responsive code. The build script creates up to 5 versions of each code sample using Prettier, and a container query displays the right one. Brotli means the filesize overhead is very small. Live demo: jakearchibald.com/2026/css-cus...
17 commentaires
?
I've been doing stuff like his forever for my interactive demos that show code. CSS-only via MQs and later container queries.
Haha I figured I wouldn't be the first. Got a link to an example?
Jake, please do not go raising the table stakes here
Good work man.
Jon Shamir @jonshamir.com · 04/09/2026 17:24
Great idea!
Ooooooh that's nice
Awesome idea!
as a quick gotcha, prettier says that their "printWidth" option isn't an absolute limit, so you might run into longer lines sometimes (see prettier.io/docs/options...)

(I'm not sure of the cases when this happens)
Options · Prettier
Prettier ships with a handful of format options.
See the first code block of jakearchibald.com/2026/goldilo... - I have it wrapping, but it preserves the indent (like VSCode).
The Goldilocks customizable select height
The 'ideal' sizing is more complicated than you think…
Rasmus Fløe @phloe.co · 04/09/2026 15:22
With responsive tabs for indentation? 😀
Lino Le Van @linolevan.com · 04/09/2026 15:18
This is so cool!!
Ethan Arrowood @arrowood.dev · 04/09/2026 14:46
desperately need this for my astro+mdx site. I decided to go with horizontal scroll and just leave the code as some default format (100 cols maybe). best compromise across mobile and desktop. This would be way better!
@nasso.dev · 04/09/2026 14:16
ive been thinking about a text editor that stores source code minified and formats it just-in-time, in the buffer

this would be awesome for it!
I've thought along those lines too. Although storing minified means bad diffs.
Zach Leatherman @zachleat.com · 04/09/2026 14:12
fascinating idea!
Good stuff!

Polypane's source panel has been using Prettier to auto-format HTML sources since I added it a few years ago, to make sure even minified HTML is readable. It's fast enough to run in a worker (at an interval) as well.

polypane.app/docs/source-...
Source panel | Polypane
The "Source" tab in the panel shows the rendered and server-sent HTML source of the current page, and you can toggle between the two with…
Anthony Frehner @frehner.me · 04/09/2026 13:58
lol I thought you had a blog post up about this, I was confused. Ignore me
How did you pick the cutoffs? I would run prettier 100 times from 20-120 columns, discard duplicates, then discard inner candidates by nearest neighbours until I reach the desired count.
Picked the numbers out of the air. There may be better options here.
Samuel @samuel.fm · 04/09/2026 13:37
oh that's amazing haha
Pre-computing them is a clever idea!

I wanted to add client side code formatting to an internal docs site we had, but didn't want to ship prettier to the client.
In hind sight your approach makes total sense, we don't need to handle arbitrary widths, they bucket very well
easrng  @easrng.net · 04/09/2026 15:38
I bet you could ship it as prettier doc nodes and just bundle the printer to skip shipping the parser
Alhadis @alhadis.bsky.social · 04/09/2026 13:42
This would be my worse nightmare, because I already forcefully reformat unreadable indentation to use tabs (since 2-space tabstops are NOT readable), and client-side formatting is something that only a client-side *code-editor* should be concerned with.
GitHub - Alhadis/Unfuck-Tabstops: Bookmarket to aggressively convert 2-space tabstops on GitHub to real tabs.
Bookmarket to aggressively convert 2-space tabstops on GitHub to real tabs. - Alhadis/Unfuck-Tabstops
Yeah, the ideas I went through:

➡️ Prettier on the client.
➡️ Diff all the phases, and create chars and line breaks that show & hide at particular widths.
➡️ Nah fuck it just render copies.
Voir le post d'origine sur Bluesky
Lien copié dans le presse-papier

Connexion

Il est temps de faire une pause

Ça fait 30 minutes que vous enchaînez les vidéos : accordez-vous 5 minutes loin de l'écran. Levez-vous, étirez-vous, buvez un verre d'eau… Les vidéos vous attendront ici.