css-modularscale

1.1.1 • Public • Published

Modular Scale

A modular scale is a list of values that share the same relationship. These values are often used to size type and create a sense of harmony in a design. Proportions within modular scales are all around us from the spacing of the joints on our fingers to branches on trees. These natural proportions have been used since the time of the ancient Greeks in architecture and design and can be a tremendously helpful tool to leverage for web designers.

Ems work especially well with modular scales as their recursive properties mimic modular scales making them more predictable and easier to manage. Pixels and other units work just fine and breakpoints in responsive web design can naturally fall on your scale to create better relevance to your text as all the values in your layout harmonize with each other.

To get started, you need to select a ratio and a base value. The base value is usually your text font size or 1em. This base size paired with a ratio such as the golden ratio or any musical proportion will create your scale of values which all share this proportion.

Install

  • npm install css-modularscale
  • then, in your css: @import "css-modularscale"

Compatability

css-modularscale is created with future CSS syntax in mind. For more information about CSS variables and the spec, consult The W3C's Working Draft on the topic. You can use any CSS "postprocessor" that has support for custom properties, such as PostCSS or Rework. If you want to get started fast, I recommend checking out the CSSNext project.

Usage

Modular Scale has two default variables that you should place with your other site wide variables. --ms-base is usually your font size or 1rem. --ms-ratio is the factor of change between each number so if the ratio is 1.5 then each number in the sequence will be 1.5 times that of the previous number.

:root {
    --ms-base: 1em;
    --ms-ratio: var(--golden);
}

Modular-scale is used as a custom property. Simply pass it through in place of any value to use a value based on a modular scale.

font-size: var(--ms2); // two up the modular scale 

Ratios

Modular scale includes functions for a number of classic design and musical scale ratios. You can add your own ratios as well.

By default, the variable --ms-ratio is set to --golden.

FunctionRatioDecimal value
--phi1:1.6181.618
--golden1:1.6181.618
--double-octave1:44
--major-twelfth1:33
--major-eleventh3:82.667
--major-tenth2:52.5
--octave1:22
--major-seventh8:151.875
--minor-seventh9:161.778
--major-sixth3:51.667
--minor-sixth5:81.6
--fifth2:31.5
--augmented-fourth1:√21.414
--fourth3:41.333
--major-third4:51.25
--minor-third5:61.2
--major-second8:91.125
--minor-second15:161.067

Add your own ratio in CSS by setting a variable and passing that to modular-scale.

:root {
    --my-ratio: calc(1 / 3.14159265);
    --ms-ratio: var(--my-ratio);
}

Changelog

Package Sidebar

Install

npm i css-modularscale

Weekly Downloads

263

Version

1.1.1

License

MIT

Last publish

Collaborators

  • vinspee