npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

modularscale-sass

v3.0.10

Published

A tool to help web designers size their type in a more meaningful way.

Downloads

42,614

Readme

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. Optionally you can add another value to create a double stranded modular scale which might be useful to create more options for in-between values. 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

Eyeglass

  • Terminal: npm install modularscale-sass --save-dev
  • SCSS: @import 'modularscale'

Webpack with sass-loader

  • Terminal: npm install modularscale-sass --save-dev
  • Webpack config: install and use sass-loader
  • SCSS: @import '~modularscale-sass/stylesheets/modularscale';

Bower

  • Terminal: bower install modular-scale --save-dev
  • SCSS: @import '../link_to_component_dir/modularscale';

Vanilla Sass

Compass (no longer being updated. Last release v3.0.2)

  • Terminal: gem install modular-scale --pre
  • Compass config: require 'modular-scale'
  • SCSS: @import 'modularscale';

Using modular scale

Initial setup and usage:

The first thing you’ll want to do when you start using modular scale is configure it to meet your needs. This is done in the $modularscale map.

$modularscale: (
  base: 1em,
  ratio: 1.5
);

You can use any unit you wish as your base and any ratio. Multiple bases can be defined for creating multi stranded scales. There is no limit here to the number of strands you use.

$modularscale: (
  base: 1em 1.2em 1.6em,
  ratio: 1.5
);

Now that we have defined your scale, we can start using it anywhere. Simply call the ms(n) function where n is the point on the scale.

h4 {
  font-size: ms(3);
}

Occasionally you may wind up with conflicts. All critical components are name-spaced to avoid conflicts with other libraries. If you do run into a conflict, ms-function() is the no-conflict function.

Multiple scale threads

Modular scale now supports different settings threads, so you can set up various threads to configure different ratios or breakpoints.

$modularscale: (
  base: 1em,
  ratio: 1.5,
  a: (
    ratio: 1.3
  )
);

To call the thread named a, call it in your function like so:

h5 {
  font-size: ms(2, $thread: a);
}

Your settings will cascade into the threads so no need to redefine a base or ratio if you want to re-use it from the main config.

If you wish to put breakpoints into your settings for use with responsive typography then there are helpers in place for this. Simply organize your config with breakpoint values from smallest to largest:

$modularscale: (
  base: 12px,
  ratio: 1.5,
  400px: (
    ratio: 1.2,
  ),
  900px: (
    base: 16px,
    ratio: 1.3,
  ),
  1200px: (
    base: 16px,
    ratio: 1.6,
  ),
);

Note that you must use the same units for both your type and your breakpoints for this to work

This technique is based on Mike Riethmuller’s Precise control over responsive typography. A fantastic technique for fluidly scaling typography.

Then, call the mixin @include ms-respond(); and a fully fluid and responsive scale will be generated.

h2 {
  @include ms-respond(font-size,5);
}

If you do happen to have any values that are just named without numbers they will be ignored by the responsive mixin, it’s smart enough to just pull values that look like breakpoints.

Note on non-integer values

Unfortunately Sass doesn’t natively support exponents. This isn’t all bad news, you can either use Compass, mathsass, or another library that has a pow() function that supports non-integer values and this plugin will pick up on that function and use it. You will then be able to write values like ms(2.5). This is also a prerequisite for target sizes below.

Target sizes

NOTE: Please see above section on non-integer values before using this feature

One of the more difficult parts of setting up your scales is finding a ratio that works for you. In many cases you know what size you want your text to be and what size you want larger headings to be. The at helper allows you to plug in a target size into the ratio value and it will generate your ratio.

$modularscale: (
  base: 16px,
  ratio: 42at5
);

Now your base is 16px and when you call ms(5) it will be 42px. Everything in-between falls neatly on a scale created with these two values.

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 ratio is set to $fifth.

Changelog

License

The MIT License (MIT)

Copyright © 2015 Scott Kellum (@scottkellum), Adam Stacoviak (@adamstac) and Mason Wendell (@codingdesigner)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

The software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and non-infringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.