{"id":96,"date":"2026-10-18T17:53:14","date_gmt":"2026-10-18T17:53:14","guid":{"rendered":"https:\/\/refracttools.com\/blog\/?p=96"},"modified":"2026-10-18T17:53:14","modified_gmt":"2026-10-18T17:53:14","slug":"variable-fonts-css","status":"publish","type":"post","link":"https:\/\/refracttools.com\/blog\/typography\/variable-fonts-css\/","title":{"rendered":"Variable fonts in CSS: weight, width and custom axes"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Variable fonts in CSS let one font file cover a whole range of styles. You control them with ordinary properties: <code>font-weight<\/code> for the weight axis, <code>font-stretch<\/code> for width, <code>font-style<\/code> for slant and italic, and <code>font-optical-sizing<\/code> for optical size. Only custom axes, such as grade or roundness, need the lower-level <code>font-variation-settings<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This guide covers the five standard axes, the <code>@font-face<\/code> setup, custom axes and the inheritance trap that catches most people, plus when a variable font actually saves bytes.<\/p>\n\n\n\n<div class=\"wp-block-group is-style-refract-takeaways is-layout-constrained wp-block-group-is-layout-constrained\">\n<h3 class=\"wp-block-heading\">Key takeaways<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A variable font stores every style along one or more axes in a single file; any value in the range works, such as a weight of 450.<\/li>\n\n\n<li>Declare ranges in <code>@font-face<\/code>, for example <code>font-weight: 100 900<\/code>.<\/li>\n\n\n<li>Use <code>font-weight<\/code>, <code>font-stretch<\/code> and <code>font-style<\/code> for registered axes; save <code>font-variation-settings<\/code> for custom ones.<\/li>\n\n\n<li>Setting <code>font-variation-settings<\/code> replaces every axis it doesn&#8217;t mention, so use custom properties to change one at a time.<\/li>\n\n\n<li>All current browsers support variable fonts.<\/li>\n<\/ul>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">What is a variable font?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A traditional family ships a separate file for each style: Light, Regular, Medium, Bold and so on. A variable font stores the outlines once, with rules for how they change along each axis. You can pick any point on that axis, so 450 or 650 is as easy as 400 or 700, and one file often replaces six or more.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to tell if a font is variable<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Check the file name.<\/strong> Variable versions are often labelled &#8220;Variable&#8221;, &#8220;VF&#8221; or with the axes in brackets, such as <code>Inter[opsz,wght].ttf<\/code>.<\/li>\n\n\n<li><strong>Check the download.<\/strong> Many families ship a folder of static files and a separate variable file. Use the variable one for the web.<\/li>\n\n\n<li><strong>Drop it into a tester.<\/strong> If it shows sliders, it&#8217;s variable; if it shows a single fixed style, it&#8217;s static.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Variable fonts also include named instances, such as &#8220;SemiBold&#8221; at weight 600. These are shortcuts to points on the axes and appear in design apps, but on the web you can use any value, not just the named ones.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The five registered axes<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><div class=\"table-scroll\" tabindex=\"0\" role=\"region\" aria-label=\"Scrollable table\"><table><thead><tr><th>Axis<\/th><th>Tag<\/th><th>CSS property<\/th><th>Example<\/th><\/tr><\/thead><tbody><tr><td>Weight<\/td><td><code>wght<\/code><\/td><td><code>font-weight<\/code><\/td><td><code>font-weight: 650;<\/code><\/td><\/tr><tr><td>Width<\/td><td><code>wdth<\/code><\/td><td><code>font-stretch<\/code><\/td><td><code>font-stretch: 87.5%;<\/code><\/td><\/tr><tr><td>Slant<\/td><td><code>slnt<\/code><\/td><td><code>font-style: oblique<\/code><\/td><td><code>font-style: oblique 10deg;<\/code><\/td><\/tr><tr><td>Italic<\/td><td><code>ital<\/code><\/td><td><code>font-style: italic<\/code><\/td><td><code>font-style: italic;<\/code><\/td><\/tr><tr><td>Optical size<\/td><td><code>opsz<\/code><\/td><td><code>font-optical-sizing<\/code><\/td><td><code>font-optical-sizing: auto;<\/code><\/td><\/tr><\/tbody><\/table><\/div><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Registered axes use lower-case tags. Optical size is usually left on <code>auto<\/code>, which lets the browser match it to the font size; setting a specific number needs <code>font-variation-settings<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setting up @font-face for a variable font<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>@font-face {\n  font-family: \"Geist\";\n  src: url(\"\/fonts\/geist-variable.woff2\") format(\"woff2\");\n  font-weight: 100 900;       \/* the font's weight range *\/\n  font-style: normal;\n  font-display: swap;\n}\n\nh1     { font-weight: 750; }\np      { font-weight: 420; }\nstrong { font-weight: 650; }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The two-value <code>font-weight<\/code> tells the browser this one file covers every weight from 100 to 900. Without the range, it treats the font as a single weight and may fake bold by thickening the outlines. If the font has a width axis, add a range for <code>font-stretch<\/code> too, such as <code>75% 125%<\/code>.<\/p>\n\n\n<aside class=\"tool-card tool-card--inline\"><span class=\"swatch\" style=\"background:linear-gradient(90deg,#13161c 0 20%,#5c6577 20% 45%,#aeb5c2 45%)\" aria-hidden=\"true\"><\/span><div class=\"tool-card__body\"><p class=\"tool-card__eyebrow\">Free tool<\/p><p class=\"tool-card__name\">Variable font playground<\/p><p class=\"tool-card__blurb\">Try every axis of a variable font on your own text, then copy the CSS.<\/p><\/div><a class=\"btn primary\" href=\"https:\/\/refracttools.com\/variable-font-playground\/\">Try it free <span aria-hidden=\"true\">\u2192<\/span><\/a><\/aside>\n\n\n\n<h2 class=\"wp-block-heading\">Custom axes and font-variation-settings<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Designers can add their own axes, written with upper-case tags: <code>GRAD<\/code> (grade) changes thickness without changing letter widths, and <code>ROND<\/code> might soften corners. These have no ordinary CSS property, so you set them with <code>font-variation-settings<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.button-label {\n  font-variation-settings: \"GRAD\" 150;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Grade is handy for hover states and dark mode: text can look slightly bolder without shifting the layout, because the letters stay the same width.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The inheritance trap<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>font-variation-settings<\/code> sets all of its axes at once. If a parent sets <code>\"GRAD\" 150, \"ROND\" 50<\/code> and a child sets only <code>\"ROND\" 100<\/code>, the child loses the grade entirely. MDN&#8217;s recommended fix is to put each axis in a custom property and set the property once:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>:root {\n  --grad: 0;\n  --rond: 0;\n}\nbody {\n  font-variation-settings: \"GRAD\" var(--grad), \"ROND\" var(--rond);\n}\n.soft { --rond: 100; }   \/* only roundness changes *\/\n.dark { --grad: -25; }   \/* only grade changes *\/<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The same reasoning is why registered axes should use the normal properties: <code>font-weight<\/code> inherits on its own, works with <code>&lt;strong&gt;<\/code> and headings, and doesn&#8217;t wipe out other settings.<\/p>\n\n\n\n<div class=\"wp-block-group is-style-refract-callout is-layout-constrained wp-block-group-is-layout-constrained\">\n<p class=\"wp-block-paragraph\"><strong>Tip:<\/strong> Weight and width can be animated with an ordinary CSS transition, which makes subtle hover effects easy. Keep them short, and turn them off under <code>prefers-reduced-motion<\/code>.<\/p>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Where to find good variable fonts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Google Fonts lists hundreds of variable families and lets you filter by axis, and most open source families on GitHub now ship a variable file alongside the static ones. Inter, Roboto Flex, Recursive and Fraunces are popular starting points because they offer more than just weight. Check the licence before self-hosting: open fonts under the SIL Open Font Licence can be served from your own domain, while commercial fonts often charge separately for web use.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Do variable fonts make pages faster?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Usually, if you use more than two or three styles. One variable file is often larger than any single static weight, but smaller than four or five static files together, and it saves the extra requests. If your site only uses Regular and Bold, two subset static files can still be lighter. Either way, subset and compress the font: the <a href=\"https:\/\/refracttools.com\/blog\/typography\/convert-ttf-to-woff2\/\">guide to WOFF2 and subsetting<\/a> covers that, and axes survive the process.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Explore a font&#8217;s axes<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Drop any font into the <a href=\"https:\/\/refracttools.com\/variable-font-playground\/\">variable font playground<\/a> to see every axis it has, drag the sliders, step through its named styles and type your own text. It writes the <code>@font-face<\/code> rule with the right ranges and a class that uses <code>font-weight<\/code>, <code>font-stretch<\/code> and <code>font-style<\/code> where it can, falling back to <code>font-variation-settings<\/code> only for custom axes. Nothing is uploaded. Then shrink the file with the <a href=\"https:\/\/refracttools.com\/font-converter\/\">font converter<\/a> and size it responsively with the <a href=\"https:\/\/refracttools.com\/fluid-typography-calculator\/\">fluid typography calculator<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Sources: <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/CSS_fonts\/Variable_fonts_guide\" rel=\"noopener\" target=\"_blank\">MDN: Variable fonts guide<\/a>.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>One variable font file can replace a whole family. Here is how the weight, width, slant and optical size axes map to CSS, how to declare them in @font-face, and how to set custom axes without the inheritance trap.<\/p>\n","protected":false},"author":1,"featured_media":95,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_refract_tool":"variable-font-playground","footnotes":""},"categories":[10],"tags":[47,46,45],"class_list":["post-96","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-typography","tag-typography","tag-variable-fonts","tag-web-fonts"],"_links":{"self":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts\/96","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/comments?post=96"}],"version-history":[{"count":1,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts\/96\/revisions"}],"predecessor-version":[{"id":113,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts\/96\/revisions\/113"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/media\/95"}],"wp:attachment":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/media?parent=96"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/categories?post=96"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/tags?post=96"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}