Tue Nov 08 2022

Flow like water ♾️

So...
We've all heard about fluid typography
There are many css or sass solutions
Since i'm using stitches.js for my site i had to translate the formula

export function flow(min, max = min * Math.sqrt(2)) {
  // set target resolutions
  const mobile = 375;
  const desktop = 1920;
  // calc variables
  var x = (max - min) / (desktop - mobile);
  var y = max - desktop * x;
  // clamp results
  return `clamp(${min}px, 100vw * ${x} + ${y}px, ${max}px)`;
}

Example Usage

<Text css={{ fontSize: flow(16) }}>{children}</Text>

Credits

Special thanks to Michael Sharanda from whom i first learned about fluid typography.