Change serif, sans-serif and monospace generic font families mapping on Linux operating system

Ubuntu Font FamilyDifferent Linux distributions map different fonts to generic font families like serif, sans-serif and monospace and thats fine. Unfortunately as a web developer I need those families consistent on all my machines and as similar as possible to generic font families mapping my code users have. Because of that the first thing I do when I decide to keep Linux distribution around is to configure serif, sans-serif and monospace generic font families mapping.

I usually do this only for my user account but it is also easy to configure this mappings globally. For per user configuration just login as target user and create file named .fonts.conf in target users home directory.

nano ~/.fonts.conf

Now you can place following inside and replace font families to font families you require for your work:

<!--?xml version="1.0"?>-->
<!--DOCTYPE fontconfig SYSTEM "fonts.dtd">-->
<!-- ~/.fonts.conf for per-user font configuration -->
            <family>Liberation Serif</family>
            <family>Liberation Sans</family>
            <family>Liberation Mono</family>

Instead of only one font family you can place multiple ones and fontconfig will search trough this list and pick first font that exists on your system. I usually place Liberation Sans (open source version of Arial) as sans-serif, Liberation Serif (open source version of Times New Roman) as serif and Liberation Mono (open source version of Courier New) as monospace but you can place any font that comes to your mind.

If you want to configure this for all users on Debian based machine like Ubuntu just place your file named 99-webfont-mapping.conf inside /etc/fonts/conf.avail/ and create symlink inside /etc/fonts/conf.d/ directory.

sudo nano /etc/fonts/conf.avail/99-webfont-mapping.conf
sudo ln -s /etc/fonts/conf.avail/99-webfont-mapping.conf /etc/fonts/conf.d/99-webfont-mapping.conf

You should reboot now for changes to take an effect. Enjoy!


A quality focused Magento specialized web development agency. Get in touch!

3 thoughts on “Change serif, sans-serif and monospace generic font families mapping on Linux operating system

  1. Gary

    Does this work for Firefox on Ubuntu? I’ve tried both the ~/.fonts.conf and the 99-webfont… variation and neither seems to change the font used by sans-serif web pages.

    My specific complaint is that capital I and lowercase l are indistinguishable in the sans-serif font. I want to replace sans-serif on my system with something that allows me to see the difference.

    1. Marko Author

      yes it works for all applications that use fontconfig settings including Ubuntu. Most sites map to sans-serif as last resort if user doesn’t have some specific font like Arial or Verdana. Because of that you would notice you changes (sans-serif family will be used) only if fontconfig is unable to find specific fonts, or fonts with metrics similar to those specific fonts.

  2. Martin

    Just dropping that here because this article was one of the few straws on my search to get better replacement for Arial on my new Kubuntu Xenial 16.04 desktop.

    Putting user config in ~./.fonts.conf is deprecated for newer fontconfig installations. Instead, fontconfig now pulls user config from ~/.config/fontconfig/fonts.conf or (better for the purpose of separation) ~/.config/fontconfig/conf.d. When put in conf.d, configuration files must be named in the form [0-9][0-9]*.conf (see /etc/fonts/conf.avail/50-user.conf and /etc/fonts/conf.d/README). Otherwise fontconfig will not respect them.

    Trying to get Arial text in Firefox rendered with Noto Sans instead of the older Liberation Sans I got this to work beautifully:



    Noto Sans

    If interested, you might want to read the full story here: Hope this helps anyone as crazy as me who comes across this post trying to get a similar setting to play.


Leave a Reply

Your email address will not be published. Required fields are marked *