Skip to content

Instantly share code, notes, and snippets.

@daliborgogic
Last active March 17, 2023 22:14
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save daliborgogic/411365e0e17710922bb45c7164a356f3 to your computer and use it in GitHub Desktop.
Save daliborgogic/411365e0e17710922bb45c7164a356f3 to your computer and use it in GitHub Desktop.
Dynamic Metrics Inter font postcss
/* css variables does't work in math... */
/* using postcss-simple-vars */
$a: -0.0223;
$b: 0.185;
$c: -0.1745;
$lineHeight: 1.4;
$fontSize: 16;
@import url('https://rsms.me/inter/inter.css');
html {
font-family: 'Inter', sans-serif;
/*
InterDynamicLineHeight produces the line height
for the given font size
function InterDynamicLineHeight(fontSize) {
const l = 1.4
return Math.round(fontSize * l)
}
*/
font-size: $(fontSize)px;
line-height: resolve(round($(fontSize) * $(lineHeight)))px;
/*
InterDynamicTracking takes the font size in points
or pixels and returns the compensating tracking in EM.
function InterDynamicTracking(fontSize) {
const a = -0.0223
const b = 0.185
const c = -0.1745;
// tracking = a + b * e ^ (c * fontSize)
return a + b * Math.pow(Math.E, c * fontSize)
}
*/
letter-spacing: resolve(round(resolve($(a) + $(b) * pow(E, resolve($(c) * $(fontSize)))), 3))em;
}
@supports (font-variation-settings: normal) {
html { font-family: 'Inter var', sans-serif; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment