1.0.0 • Published 4 years ago

molten-type v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

molten-type

A set of modular scales for fluid typography that responds to viewport changes. It combines the relationship between a text's font size, its line height and its line length. Instead of adjusting just the font size on a breakpoint by breakpoint basis, a molten type will adjust all three for every viewport size, as the viewport changes.

So what is a modular scale? To put it simply, a modular type scale is a list of font sizes that work well together because they increase by the same ratio. We start with a base font size and multiply it by the ratio to obtain the font sizes we can then use in our CSS.

For example, having a base size of 16px and a ratio of 1.5 will yeild us a list of 16px, 24px, 36px, 54px, 81px, etc.

In addition to changing the font size based on a ratio, molten type will also adjust the font's line height and, if a variable font is used, its font weight. It all happens automatically for each viewport width, and each viewport width will take into account the type scale ratio.

molten type demo

Out of the box, molten type has the following type scales:

NameRatioFile
Base1.000index.css
Minor Second1.067minor-second.css
Major Second1.125major-second.css
Minor Third1.200minor-third.css
Major Third1.250major-third.css
Perfect Fourth1.333perfect-fourth.css
Augmented Fourth1.414augmented-fourth.css
Perfect Fifth1.500perfect-fifth.css
Golden Ratio1.618golden-ratio.css

Additionally, you can set the ratio yourself by adding the index.css file and overwriting the root CSS property for --type-scale.

<link rel="stylesheet" href="node_modules/molten-type/index.css" />
<style>
  :root {
    --type-scale: 0.8;
  }
</style>

Usage

First install the package from npm:

npm install --save molten-type

Or with yarn

yarn add molten-type

Then link to the stylesheet you want to use:

<link rel="stylesheet" href="node_modules/molten-type/major-third.css" />

Or use it in your SPA or similar. For example, in a Gatsby website, in gatsby-browser.js:

import 'molten-type/major-third.css';

Browser support

If you still have to care about IE11 and below, you cannot use CSS variables. You also need to support calc(), which is a bit flaky in IE11 and below, as well Safari and iOS Safari 6 and 7 (which won't support viewport units in calc()). Sad face!

BrowserSupported
Google ChromeSupported
SafariSupported
FirefoxSupported
EdgeSupported
OperaSupported
Internet ExplorerNot supported

Contributing

For details, check out the Contributing guide.

LICENSE

MIT

Further reading

molten type would not be possible without the teachings and writings of these folks: