Change hard coded font ratios to variables

AI-generated summary

In the UX category, probus proposes replacing hard-coded font ratios in Discourse CSS with variables to simplify base font size adjustments. Currently, font sizes are defined in em relative to a 14px base (e.g., 1.143em equals 16px). probus argues that changing the base size to something more standard like 16px results in awkward pixel values (e.g., 18.288px), which can cause poor font rendering on low-resolution Windows screens and requires tedious manual updates across dozens of CSS rules. sam requests visual evidence of the rendering issues, but probus declines, noting the lack of a suitable test setup. Instead, probus provides a comprehensive list of the specific em values currently in use (ranging from 0.714 for 10px to 2 for 28px) and suggests mapping them to semantic variables (e.g., xxs to xxl) to make future typography changes straightforward and consistent.

Font sizes in Discourse css are expressed as em in relation to 14px. So, there are for example multiple rows in the css where font size is 1.143em, which translates to 16px. Personally, I find 14px quite small for most if not all fonts for body text.

The problem is, if you change the base font size all the other sizes no longer conform to nice round numbers. For 16px base font size 1.143em becomes 18.288px. So you have to go trough the css and change font size in dozens of places one by one anyway or risk bad font rendering on some systems. This makes changing the font size pretty painful.

There are only a handful of different font sizes used so mapping them to variables should be pretty straightforward and make changing font (sizes) much easier.

5 « J'aime »

Can you expand on this issue with a screenshot or two?

cc @awesomerobot

Unfortunately not. This is pretty basic stuff for (Windows) font rendering in low resolution screens, but I don’t have such setup.

Here’s a list of the main font sizes, basically I suggest replacing these with variables named xxs-xxl or — +++ trough out the css.

0.714 //10px
0.857 //12px
0.929 //13px
1 //14px
1.071 //15px
1.143 //16px
1.214 //17px
1.286 //18px
1.5 //21px
1.571 //22px
1.643 //23px
1.714 //24px
1.786 //25px
2 // 28px

I left a couple out (if I remember correctly there are some nested rules) and the larger sizes obviously don’t suffer as much as the smaller.