Fontsource Logo

Documentation

Faces Mixin

The font faces mixin allows you to generate a highly customizable CSS file for your font by modifying various @font-face variables. This guide explains how to use the Faces mixin in your Sass/SCSS projects.

Installation

To use the Faces mixin, you must install the @fontsource-utils/scss helper package and the specific font package you want to customize:

⬤⬤

npm install @fontsource-utils/scss

sh

Then, import the Fontsource mixins in your Sass/SCSS file using the @use rule:

⬤⬤

@use "pkg:@fontsource-utils/scss" as fontsource;
@use "pkg:@fontsource-variable/recursive/scss" as recursive;

scss

Usage

Once you have imported the mixin, you can use it to generate a CSS file with customized font variations. Here’s an example that generates a CSS file similar to recursive/latin-500-italic.css:

⬤⬤

@include fontsource.faces(
$metadata: recursive.$metadata,
$subsets: latin,
$weights: 500,
$styles: italic
);

scss

You can customize the font variations by specifying different subsets, weights, and styles. Use the all option if you want to include all available options for a specific property. Here’s an example that includes multiple subsets, weights, and all available styles:

⬤⬤

@include fontsource.faces(
$metadata: recursive.$metadata,
$subsets: (
latin,
greek,
),
$weights: (
300,
400,
800,
),
$styles: all
);

scss

Mixin Arguments

The Faces mixin accepts several properties as arguments, allowing you to customize various aspects of the font. Here are the available arguments::

VariableDescriptionOptionsDefault
$familyFont family name (see font-family)Any stringMetadata default used (e.g. “Open Sans”)
$displayHow the font is displayed when loading (see font-display)One of: auto, block, swap, fallback, optionalswap
$formatsList of included font file formats (see src)all, or any of: woff, woff2all
$subsetsList of included subsetsall, or any of the subsets listed for the fontMetadata default used (e.g. latin)
$weightsList of included weights (see font-weight)all, or any of the weights listed for the fontMetadata default used (e.g. 400)
$stylesList of included styles (see font-style)all, or any of the styles listed for the font (usually normal and italic)Metadata default used (e.g. normal)
$axesList of included variable font axes (see Variable fonts guide)all (which uses full), or any of the axes listed for the fontfull

The following advanced properties shouldn’t need to be modified as often, but are still available for use:

VariableDescriptionDefault
$metadataMetadata map, which is used for resolving default options, available properties, and source pathsDefault package metadata (located in scss/metadata.scss)
$directoryBase directory used for the font source pathsDefault package path (e.g. ~@fontsource/open-sans/files)

Global Configuration

The arguments for the Faces mixin can also be set directly on module import, which will set the new defaults throughout different uses of the mixin. Here’s an example:

⬤⬤

@use "@fontsource-utils/scss" as fontsource with (
$weights: (
300,
700,
),
$family: "Fontsource Custom"
);
@include fontsource.faces(
$metadata: recursive.$metadata
// The global configuration can still be overwritten through arguments
$family: "Recursive Other"
);

scss

By setting the arguments on module import, you can easily configure the defaults for the Faces mixin.