Google Fonts now fully supports variable fonts in the v2 API update. We’llexplain how to call both single and multiple font families and how to specifyaxes ranges. For an in-depth look into variable fonts, learn more with thisinteractively illustrated brochurefrom David Berlow at TypeNetwork.
May 19, 2020 Google Fonts is fast. Now it’s faster. While first paint either remained the same or got slower, first contentful paint either remained the same or got faster, and in the case of CSS Wizardry, first web font was a staggering 600ms faster than the previous iteration. The @font-face CSS rule allows web developers to specify online fonts to display text on their web pages. By allowing authors to provide their own fonts, @font-face eliminates the need to depend on the limited number of fonts users have installed on their computers. After the color, the font is probably the most basic property of a page. On this page I won't show any 'tricks,' but I will show the range of font variations that CSS allows. Since not all fonts are available on all computers (there are thousands of fonts, and most are not free), CSS provides a system of fallbacks. How to Import Google Fonts in CSS File. An essential part of any design is the chosen font. Google Fonts is a free service of web fonts that allows us to use a large variety of fonts in our CSS file. In this snippet, you'll find two ways of importing Google Fonts. How to use Google fonts in CSS? It is an important aspect of any web design to choose the right font for the webpage. The use of Google fonts is advantageous because we get elegant fonts for our website. The Google fonts API makes it easier and quicker for everyone to use web-fonts. These fonts have been tested on various browser configurations.
What’s new
It all starts with a new base URL:
The syntax for specifying styles within each family has changed to describevariable font ‘design spaces.’
Quickstart guides
Copy and paste this HTML into a file:
Using a browser to open the file, the page should render the text, “Making theWeb Beautiful”, in the Crimson Pro font.
Multiple families
To request multiple families, specify the
family=
param for each family.For example, to request the fontsCrimson Pro andLiterata:
Copy and paste this HTML into a file:
Using a browser to open the file, the page should render the text, “Making the Web Beautiful”, first in Crimson Pro then in Literata.
Making the Web Beautiful!
Axis ranges
Variable fonts offer continuous ranges of styles, often without additionallatency. This is relevant to responsive design.This dynamic typography uses continuous ranges of styles, offering all theweights between 100 and 900 on a page, and responsively varying the weightbased on some conditions.
To request a range of a variable font axis, join the 2 values with
.
Font(s) | Request |
---|---|
Crimson Pro [wght 200-900] | https://fonts.googleapis.com/css2?family=Crimson+Pro:[email protected] |
Crimson Pro Italic [wght 200-900] | https://fonts.googleapis.com/css2?family=Crimson+Pro:ital,wght@1,200.900 |
Crimson Pro Bold Italic & [wght 200-900] | https://fonts.googleapis.com/css2?family=Crimson+Pro:ital,wght@0,200.900;1,700 |
Your browser does not appear to support variable fonts (caniuse).On a browser that does support font variations, the following text should renderCrimson Pro as a smooth set of weights from 400 to 500. CSS animations can makethe text smoothly vary the style on interaction.
If your browser fully supports variable fonts (caniuse),then the following text should render Crimson Pro as a smooth set of weights from400 to 500. CSS animations can make the text smoothly vary the style on interaction.
Making the Web Beautiful!
Making the Web Beautiful!
Making the Web Beautiful!
Individual styles, such as weight
Without style specifications, the API provides the default style of therequested family. To request other individual styles, such as specific weights,append a colon (:) after the name of the font family, followed by a list of axisproperty keywords in alphabetical order, an at sign (@), and one or more listsof values for those axis properties.
These examples show this in action.
Font(s) | Request |
---|---|
Crimson Pro (default) | https://fonts.googleapis.com/css2?family=Crimson+Pro |
Crimson Pro Bold | https://fonts.googleapis.com/css2?family=Crimson+Pro:wght@700 |
Crimson Pro Regular & Bold | https://fonts.googleapis.com/css2?family=Crimson+Pro:wght@400;700 |
Crimson Pro Bold & Bold Italic | https://fonts.googleapis.com/css2?family=Crimson+Pro:ital,wght@0,700;1,700 |
Google Fonts lists all the styles available for each font family.
Default style
When a request doesn’t specify a position or range for an axis, the defaultposition will be used. The default position of the italic axis is 0 (normal) andthe default for the weight axis is 400 (regular).
For families with axes that don’t contain the default position, requests that donot specify positions for those axes will fail. For example, when requesting afamily with a weight axis ranging from 500 to 900, the weight position must bespecified.
Non-standard weights
With static fonts, styles of weight are usually specified as multiples of 100(e.g. 300, 400, 700). Variable fonts offer both the standard weights andintermediate weights. To render an intermediate weight:
Your browser does not appear to support variable fonts (caniuse). On a browser that does support font variations, the following text should render Crimson Pro at visually distinct weights of 400, 450, and 500.
If your browser fully supports variable fonts (caniuse), the following text should render Crimson Pro at visually distinct weights of 400, 450, and 500.
Making the Web Beautiful!
Optimizing for latency and file size
Be precise about the styles you are using. The API delivers the requested stylesin the most compact set of fonts. Requesting unused styles may cause your usersto download more font data than they need, causing more latency. If you use only3 specific weights, specify them in your request as individual styles. If youuse a continuous range of weights, specify that weight range in your request.
Use font-display
Google Fonts Css Stylesheet
The font-displayproperty lets you control what happens while the font is still loading orotherwise unavailable. Specifying a value other than the default
auto
isusually appropriate.![Google Fonts Css Google Fonts Css](https://mk0designbombsg12amh.kinstacdn.com/wp-content/uploads/2017/03/google-fonts-css.jpg)
Podgrasp 2 1 0 – podcast player. Pass the desired value in the
display
parameter:Optimizing your font requests
Oftentimes, when you want to use a web font on your site or application, youknow in advance which letters you'll need. This often occurs when you're using aweb font in a logo or heading.
In these cases, you should consider specifying a
text=
value in your fontrequest URL. This allows Google Fonts to return a font file that's optimized foryour request. In some cases, this can reduce the size of the font file by up to90%.To use this feature, simply add
text=
to your API request. For example, ifyou're only using Inconsolata for the title of your blog, you can put the titleitself as the value of text=
. Here’s what the request would look like:As with all query strings, you should URL-encode the value:
This feature also works for international fonts, allowing you to specify UTF-8characters. For example, ¡Hola! is represented as:
Forming API URLs
Strictness
As a general note, the updated CSS API is more strict about what requests areaccepted than the original CSS API.
General guidelines:
- List axes alphabetically
- Axis value groups (i.e. tuples) need to be sorted numerically
- Tuples can’t overlap or touch (e.g. wght 400.500 and 500.600)
API URL Specification
/css2?family=<spec>[&family=<spec>..][&text=<text>][&display=<display>]
spec
: <family_name>[:<axis_tag_list>@<axis_tuple_list>]
family_name
: Name of the font familyaxis_tag_list
: <axis>[,<axis>..] // Sorted alphabetically
axis
: An axis tag, e.g. ital
, wdth
, wght
axis_tuple_list
: <axis_tuple>[;<axis_tuple>..]
axis_tuple
: <value>[,<value>..] // Same length as axis_tag_list
value
: <range>
| <float>
range
: <float>.<float>
float
: A value within the range of the corresponding axistext
: The text that will be displayed in the requested typefaceLegacy browser support
Browsers without variable font support may not be able to display your design asintended. Check browsers’ variable font support on caniuse.
Using Google Fonts
By practicing progressive enhancement,you can avoid unexpected behavior in those older browsers. Use
@supports
queries in your CSS to gate variable font features.In this example, we'd like to use weight 450 of Markazi Text, but will have tofall back to either Regular (weight 400) or Medium (weight 500) when variablefont features aren't supported:
The CSS request
Markazi+Text:wght@450
sends weight 450 to clients that supportvariable fonts and weights 400 and 500 to those that don’t. In general, thefallbacks around the range of your request will be available in legacy browsers.Axis | Fallbacks |
---|---|
ital | 0, 1 |
wght | 100, 200, 300, 400, 500, 600, 700, 800, 900 |
Cook serve delicious 2 2 6 0 m 1 1. These examples show what styles would be available on legacy browsers for a fewdifferent requests.
Request | Styles available on legacy browsers |
---|---|
ital@0 | ital@0 |
wght@500 | wght@500 |
wght@432 | wght@400;500 |
[email protected] | wght@400;500;600 |
![Google Fonts Css Google Fonts Css](https://i1.wp.com/css-tricks.com/wp-content/uploads/2020/07/image-15.png?resize=1024%2C1021&ssl=1)
Available variable fonts
A table of the variable fonts available in the v2 API can be found here.
Google Fonts Css Wordpress
Further reading
Google Fonts
- See a complete list of font families provided by the Google Fonts API onGoogle Fonts.
- Learn more about how the Google Fonts API works on theTechnical Considerations page.