Search code examples
cssfontswebfontsfont-familygoogle-font-api

Is it possible to specify custom name for a Google Font?


Here is a sample CSS

h1 {
   font-family: 'header-font', arial, sans-serif;
}

p {
   font-family: 'paragraph-font', arial, serif;
}

Is it possible to load any remote Google Font (let say 'Lato') so that it's family name in CSS would be 'header-font'?

Edit: The idea behind this is to be able to easily swap fonts in a WP theme. Unfortunately using variables in CSS preprocessors is not an option in my case.


Solution

  • Yes, you can give any name you want when you define the font family in the @font-face style declaration and use that name to reference it later in the stylesheet.

    @font-face
    {
      font-family: whateverYouWant;
      src: url('example.ttf'),
           url('example.eot');
           ... /* and so on */
    }
    

    Whatever you name the style as in the font-family property is how it will be referred to from the rest of the document. However I don't know how it competes with local font files (so if you tried to name a custom font Arial I'm not sure what you would get - the custom font or the real Arial). I don't know why you would do that anyway though.