Last active
February 10, 2025 15:32
-
-
Save daliborgogic/411365e0e17710922bb45c7164a356f3 to your computer and use it in GitHub Desktop.
Dynamic Metrics Inter font postcss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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; } | |
} |
I've created small postcss plugin to insert dynamic metrics, see https://www.npmjs.com/package/postcss-dynamic-metrics
@NikolayFrantsev please credit @rsms in npm package.
@daliborgogic I do believe what links to original author and idea are already there in source code and documentation, do you want something more?
@NikolayFrantsev it's ok from my side 👍🏻. I think @rsms will agree
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why did you pick a dynamic way to mention line height and tracking? Can you refer me to a place where I can read more about these equations and the reasons to use these over others?