Just use the font and font-family properties as if they were magic.
/* before *//* after */
- Want to use Google Fonts? I’ll add them for you.
- Want to use Material Icons?
- Want to use the visitor’s local copy of a font? Done.
- Want to host your own fonts? Just tell me where they are, and I’ll do the rest.
- Want to load a font async and only use it after it has been loaded? I can do that too.
- Want to use Bootstrap typography? Beautiful, fully-stacked families for serif, sans-serif, and monospace are waiting for you.
Seriously, never write a
@font-face rule again.
Need more? Request additional magic by creating an issue.
Add Font Magician to your build tool.
npm install postcss postcss-font-magician --save-dev
yarn add postcss postcss-font-magician --dev
Use Font Magician in your script:
const fs = ;const postcss = ;const pfm = ;;
Use Font Magician in your webpack.config.js:
moduleexports =plugins:'postcss-font-magician':variants:'Roboto Condensed':'300':'400':'700':foundries: 'google'
loader: 'postcss-loader'options:config:path: 'path/to/postcss.config.js'
Use Font Magician in your Gruntfile:
Use Font Magician in your Gulpfile:
var postcss = ;gulp;
Want to download only specific font weights, styles and formats?
variants:'Open Sans':'300': 'woff, eot, woff2''400 italic': 'woff2';
The plugin will download the font only selected weights, styles and formats.
Need to support unicode-range? You can use both the names of the subsets of Google fonts (e.g. 'latin-ext' or 'cyrillic') and specific unicode ranges values. You can use it as a second element in an option array.
variants:'Open Sans':'300': 'woff2' 'cyrillic-ext, greek''400 italic': 'woff2' 'U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF';
Need to support font-stretch? You can use it as a 2nd or 3rd params in an option key.
variants:'Open Sans':'300 ultra-condenced': 'woff, eot, woff2''400 italic': 'woff2''400 italic semi-expanded': 'woff2';
Need to control how custom fonts display when they loading? You can use font-display css rule.
Have a directory of self-hosted fonts?
hosted: './src/fonts' /custom/path/to/fonts/on/site;
The directory will be scanned for font files, which will be read and automatically added if they are used in the document.
Please note that at the moment the plugin doesn't detect woff2 fonts
The first argument of
hosted array is required and it should be a path that related to the project root. i.e.
In this case, the path to the fonts folder structure must match the structure of the path to the fonts folder on the server, because the path will be relative css file.
The second argument of
hosted array is optional and it can be an arbitrary path which should match the fonts directory on the site.
Prefer another name for particular fonts?
aliases:'sans-serif': 'Source Sans Pro';
@font-face rule will be updated so that your alias key is the new name of the font family.
You can also use the 'aliases' option with other options, i.g with the 'variants'
aliases:'sans-serif': 'Source Sans Pro'variants:'sans-serif':'400': 'woff';
Need to load the fonts asynchronously?
Want to control which font formats are used?
formats: 'woff2 woff';
eot are enabled.
Supported formats include
Want to enable specific foundries? Provide a space-separated list or array:
foundries: 'bootstrap google';
By default, all foundries are enabled.
Supported foundries include
Need something very specific? I can do that, too.
custom:'My Special Font':variants:normal:400:url:woff2: 'path/to/my-body-font-normal-400.woff2'woff: 'path/to/my-body-font-normal-400.woff'700:url:woff2: 'path/to/my-body-font-normal-700.woff2'italic:400:url:woff2: 'path/to/my-body-font-italic-400.woff2';
Do you want to control the font URL-address protocol?
By default, 'http/https' protocol is removed from the font url. Supports any string values, eg - '', 'http:' or 'https:'
Look forward to more magic, like:
- Support for the TypeKit foundry.
- Option to warn you when unmatched typefaces are used.