
Security News
Open Source CAI Framework Handles Pen Testing Tasks up to 3,600Γ Faster Than Humans
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600Γ faster than humans.
google-fonts-css2
Advanced tools
β οΈIf you were using the v1 of this package check the new API below, it is slightly different.β οΈ
Read on for more information. Feel free to open issues or PRs.
You say: Gimme Open Sans, from light to bold, italic. condensed and normal!
This package is bundled to be used in multiple environments (ESM, CJS, UMD).
Check the /dist
folder for enviroment options.
npm i google-fonts-css2
yarn add google-fonts-css2
<!-- directly in browser, note the /dist/umd path -->
<script src="https://cdn.jsdelivr.net/npm/google-fonts-css2@2.0.0/dist/umd/index.min.js"></script>
You can seamlessly import
or require
:
import { getGoogleFontsUrl, getGoogleFontsUrlSimple } from "google-fonts-css2"
or
const { getGoogleFontsUrl, getGoogleFontsUrlSimple } = require("google-fonts-css2")
or
For HTML check the codepen:
https://codepen.io/adrianotirloni/pen/ExEWbdd
This function calls getGoogleFontsUrl but with simpler argurments and reduced options.
Arguments: Any number of strings or objects.
Strings: Directive family style strings - All spaces and cases are removed from the string, except for the Font Family name.
Objects: Directive family style objects or a options object.
Strings format: "<case-sensitive-spaced font name>
,<weights>
,<?italic> or <?widths>
"
Objects
//Open Sans - Named regular weight
getGoogleFontsUrlSimple('Open Sans, regular')
//=> https://fonts.googleapis.com/css2?family=Open+Sans:wght@400&display=auto
//Open Sans - Named regular weight, with options object
getGoogleFontsUrlSimple(
{display: "swap", onlyThisCharacters: "abcd"},
"Open Sans, regular"
)
//=> https://fonts.googleapis.com/css2?family=Open+Sans:wght@400&display=swap&text=abcd
//Multiple arguments, multiple fonts, unordered
getGoogleFontsUrlSimple("Open Sans, 300, italic", {display: "swap"}, "Lato, regular")
//=> https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@1,300&family=Lato:wght@400&display=swap
//Open Sans - Numbered regular weight
getGoogleFontsUrlSimple("Open Sans, 400")
//=> https://fonts.googleapis.com/css2?family=Open+Sans:wght@400&display=auto
//Open Sans - Multiple Named and Numbered weight
getGoogleFontsUrlSimple("Open Sans, regular & 600")
//=> https://fonts.googleapis.com/css2?family=Open+Sans:wght@400&family=Open+Sans:wght@600&display=auto
//Open Sans - Multiple Named weight
getGoogleFontsUrlSimple("Open Sans, regular & semibold & bold")
//=> https://fonts.googleapis.com/css2?family=Open+Sans:wght@400&family=Open+Sans:wght@600&family=Open+Sans:wght@700&display=auto
//Open Sans - Ranged weight
getGoogleFontsUrlSimple("Open Sans, 300..800")
//=> https://fonts.googleapis.com/css2?family=Open+Sans:wght@300..800&display=auto
//Open Sans - Regular Italic
getGoogleFontsUrlSimple("Open Sans, 400, italic")
//=> https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@1,400&display=auto
//Open Sans - Full weight range, italic and named width
getGoogleFontsUrlSimple("Open Sans, 300..800, italic, condensed & normal")
//=> https://fonts.googleapis.com/css2?family=Open+Sans:ital,wdth,wght@1,75,300..800&family=Open+Sans:ital,wdth,wght@1,100,300..800&display=auto
//Open Sans - Full weight range, WITHOUT italic and named width
getGoogleFontsUrlSimple("Open Sans, 300..800, condensed & semiCondensed & normal")
//=> https://fonts.googleapis.com/css2?family=Open+Sans:wdth,wght@75,300..800&family=Open+Sans:wdth,wght@87.5,300..800&family=Open+Sans:wdth,wght@100,300..800&display=auto
//Open Sans - Full weight range, with italic and full ranged width
getGoogleFontsUrlSimple("Open Sans, 300..800, 75..100, italic")
//=> https://fonts.googleapis.com/css2?family=Open+Sans:ital,wdth,wght@1,75..100,300..800&display=auto
The full base function to construct the urls. Check a live example here: https://codepen.io/adrianotirloni/pen/wvmJxpG
'auto' | 'block' | 'swap' | 'fallback' | 'optional'
Any number of directive pairs: <axisDirective>: <axisOption>
Axis Directive: wght
(axis symbol) or weight
(humanized name)
ital
or italic
, XOPQ
or thickStroke
Axis Option: Number, String or Range
[Number, Number]
or [String, Number]
or [String, String]
or "StrNumber..StrNumber"
getGoogleFontsUrl([
{
family: 'Roboto Flex',
styles: [
{weight: '800..1000', width: [25, 150], slant: -5, figureHeight: 500},
{weight: 300},
{weight: 400},
]
},
{
family: 'Open Sans',
styles: [
{weight: '400', italic: 1},
]
}
], 'swap', 'abcdefgh')
getGoogleFontsUrl(
[
{
family: 'Material Icons',
styles: [
{ wght: '500', wght: '501' }
]
}
],
'swap'
)
getGoogleFontsUrl([
{
family: 'Roboto Flex',
styles: [
{ weight: '100..500', width: [-10, 0] }
]
}
], 'swap')
Android, IOS and Flutter implementation are not the same as web implementation https://developers.google.com/fonts/docs/android, so is out of the scope of this package.
(If you know a library for tose tools open a PR to this document listing it here)
Google Fonts has as of today 1429 font families, of those, 1176 are regular fonts.
Regular Fonts are those that don't have a variable directive axis, like weight
.
As an example, a regular font will have 400
,500
,600
weight
.
A Font with a variable weight axis
will have every integer from 400 to 600. (401
, 476
... 599
, 600
)
A Variable Font can have one or multiple directive axis as a varaible axis. A variable font can have standard weights
(400
,500
,600
) but a variable width
axis (from 1 to 150). This font will be considered variable.
You can check all variable fonts and their directive axes on this link: https://fonts.google.com/variablefonts
Variable or Regular fonts may have any number of directive axes.
Google API will only accept the axis symbol on a specific order, to make readability better this package will allow the use of the case-sensitive symbol
AND/OR human readable name
italic: ital
opticalSize: opsz
slant: slnt
weight: wght
width: wdth
ascenderHeight: YTAS
casual: CASL
counterWidth: XTRA
cursive: CRSV
descenderDepth: YTDE
figureHeight: YTFI
fill: FILL
grade: GRAD
lowercaseHeight: YTLC
monospace: MONO
softness: SOFT
thickStroke: XOPQ
thinStroke: YOPQ
uppercaseHeight: YTUC
You can read about each on: https://fonts.google.com/variablefonts#axis-definitions
weight or wght
, opticalSize or opsz
)wght
) and uses the latest one.slant -10
the URL will properly be created BUT Google will return a 400
answer as the slant directive is not avaliable for Open SansFAQs
A Javascript package to integrate with Google Fonts API.
We found that google-fonts-css2 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600Γ faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.