Death to px, long live ch! – Terence Eden’s Blog
Theme Switcher:
🌒 Dark
🌞 Light
📰 eInk
💻 xterm
🥴 Drunk
👻 Nude
♻️ Reset
Pixels are a lie. Even if you think you're drawing something with "pixel perfect" accuracy, your monitor is lying to you. There is no grid of platonically perfect squares.
In CSS, pixels are a double lie:
Note that 1px doesn't necessarily equal one physical device pixel. On HD displays, it may span multiple physical pixels. Similarly, 1cm in CSS often doesn't correspond to one hundredth of SI meter. On a large TV screen, it typically is longer than that. The lengths are perceptual: 16px looks roughly the same on a phone, laptop, or TV screen at typical viewing distance.
This blog is primarily text based. I want the width of the text to be readable for the average human. So, rather than setting the main width to be a percentage of the screen, I set it based on character width using the ch unit - which isn't exactly a character but good enough for my purposes:
⧉ CSS--width-content: min(75ch, 100%);
main {<br>max-width: var(--width-content);
When it comes to padding and margins, the same is true. If I want a gap around an element, I want that gap to be in proportion to the text inside it.
For widths, it makes sense to re-use the ch unit. I want the gap to be in proportion to the text.
But for height, perhaps it doesn't make sense to express vertical distance on character width? In which case the ex unit can be used. It is the size of a typical lower-case letter.
Just like my idea to eliminate CSS classes from my HTML, it's possible to go too far with this. I haven't changed every reference from px to ch, I'm just experimenting to see if it works.
There's nothing wrong, immoral, or evil about using px - or any other measure unit. Using ch and ex fit with my particular proclivities.
Share this post on…
try {<br>await navigator.share({url:u});<br>} catch {<br>// Show an alert if the share failed. Likely means no share support.<br>alert('Copied URl to clipboard');<br>})()" style=cursor:pointer;>
Voluntary Paywall
Enjoyed this post? Show your support and pay the author.
2 thoughts on “Death to px, long live ch!”
Jeff Sonstein
in my experience, relative CSS measures are pretty much always more useful than absolute measures like px. nice piece.
Reply 2026-08-23 13:01
Shiv J.M.
@Edent Just don’t be like me and continually confuse yourself and wonder why your `padding: 0.75en` has no effect…
Reply | Reply to original comment on mastodon.social 2026-08-23 13:05
More comments on Mastodon.
What are your reckons?
Cancel reply
All comments are moderated and may not be published immediately. Your email address will not be published.
Comment:
See allowed HTML elements:
Your Name (required):
Your Email (required):
Your Website (optional):
To respond on your own website, write a post which contains a link to this post - then enter the URl of your page here. Learn more about WebMentions.
URL/Permalink of your article
🔎 Search
Search for:
🗓️ Explore The Archives
2026
January<br>27 posts<br>February<br>28 posts<br>March<br>23 posts<br>April<br>24 posts<br>May<br>19 posts<br>June<br>17 posts<br>July<br>17 posts<br>August<br>38 posts<br>September
October
November
December
2025
January<br>17 posts<br>February<br>20 posts<br>March<br>23 posts<br>April<br>22 posts<br>May<br>16 posts<br>June<br>28 posts<br>July<br>24 posts<br>August<br>20 posts<br>September<br>15 posts<br>October<br>16 posts<br>November<br>17 posts<br>December<br>15 posts
2024
January<br>31 posts<br>February<br>29 posts<br>March<br>31 posts<br>April<br>30 posts<br>May<br>31 posts<br>June<br>30 posts<br>July<br>19 posts<br>August<br>18 posts<br>September<br>18 posts<br>October<br>29 posts<br>November<br>31 posts<br>December<br>30 posts
2023
January<br>31 posts<br>February<br>28 posts<br>March<br>31 posts<br>April<br>30 posts<br>May<br>31 posts<br>June<br>30 posts<br>July<br>31 posts<br>August<br>31 posts<br>September<br>30 posts<br>October<br>31 posts<br>November<br>30 posts<br>December<br>31 posts
2022
January<br>30 posts<br>February<br>23 posts<br>March<br>15 posts<br>April<br>19 posts<br>May<br>19 posts<br>June<br>19 posts<br>July<br>19 posts<br>August<br>18 posts<br>September<br>12 posts<br>October<br>8 posts<br>November<br>30 posts<br>December<br>31 posts
2021
January<br>31 posts<br>February<br>28 posts<br>March<br>31 posts<br>April<br>30 posts<br>May<br>31 posts<br>June<br>30 posts<br>July<br>31 posts<br>August<br>31 posts<br>September<br>30 posts<br>October<br>31 posts<br>November<br>30 posts<br>December<br>31 posts
2020
January<br>31 posts<br>February<br>29 posts<br>March<br>31 posts<br>April<br>30 posts<br>May<br>31 posts<br>June<br>30 posts<br>July<br>31 posts<br>August<br>31 posts<br>September<br>30 posts<br>October<br>31 posts<br>November<br>30 posts<br>December<br>31 posts
2019
January<br>31 posts<br>February<br>12 posts<br>March<br>17 posts<br>April<br>12 posts<br>May<br>12 posts<br>June<br>10 posts<br>July<br>7 posts<br>August<br>5 posts<br>September<br>6 posts<br>October<br>14 posts<br>November<br>30 posts<br>December<br>17 posts
2018
January<br>8 posts<br>February<br>4 posts<br>March<br>6 posts<br>April<br>14 posts<br>May<br>5 posts<br>June<br>6 posts<br>July<br>6 posts<br>August<br>13 posts<br>September<br>14 posts<br>October<br>8 posts<br>November<br>30 posts<br>December<br>4 posts
2017
January<br>12 posts<br>February<br>9 posts<br>March<br>9 posts<br>April<br>4 posts<br>May<br>10 posts<br>June<br>5 posts<br>July<br>5 posts<br>August<br>6 posts<br>September<br>3 posts<br>October<br>4 posts<br>November<br>30...