Proper High DPI font scaling in Firefox on Linux

macOS supports high DPI displays particularly well and exposes DPI scaling as a 5-step gradient. Over on the Linux-side, however, things are far less rosy, with wild differences between distros.

Linux Mint, the distro I ended up settling on, had no trouble consistently recognizing my 4K display, over my [way too expensive] USB-C-to-HDMI interface. DPI scaling is chiefly exposed as Text Scaling, which works fine for the most part. However, there are still applications that don’t always pick up on this setting and insist on displaying text at its na[t]ive resolution. It’s pretty obvious that displaying text at 1080p on a 13″ screen, or 4K on a 27″ display, is far from ideal…

On such app is Firefox, for some reason. Luckily, Firefox’s intrepid about:config dialog exposes just the setting we need to override whatever its default behavior is. As fedoramagazine.org describes it:

find the key layout.css.devPixelsPerPx and then change the value from -1.0 to 2

Screenshot by fedoramagazine.org

For reference, I set mine to 1.5 for a 4K screen displayed on a 27″ display. Note that the entirety of Firefox’s UI scales along with any web content. If you’re running multiple screens with different resolutions and sizes, you will notice that this value is system-global, as opposed to per-screen. In other words, it won’t be a one-size-fits-all solution, but good enough for me, for now.