• Stars
    star
    370
  • Rank 115,405 (Top 3 %)
  • Language
    JavaScript
  • Created over 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Automagical responsive typography, built on PostCSS

PostCSS Responsive Type

NPM version NPM downloads Build Status

Generate automagical fluid typography, with new responsive properties for font-size, line-height, and letter-spacing. Built on PostCSS.

Responsive Type Demo

Inspired by this post.

Part of Rucksack - CSS Superpowers

Contents

Usage

Quick start

html {
  font-size: responsive;
}

Pro tip: set a reaponsive font-size on html and use rem units throughout your project to make your whole UI fluid

Specify parameters

Units can be in px, rem, or em. When using em units, be sure that the font-range is specified in em as well.

html {
  font-size: responsive 12px 21px; /* min-size, max-size */
  font-range: 420px 1280px; /* viewport widths between which font-size is fluid */
}

Expanded syntax

html {
  font-size: responsive;
  min-font-size: 12px;
  max-font-size: 21px;
  lower-font-range: 420px;
  upper-font-range: 1280px;
}

Responsive line-height and letter-spacing

PostCSS Responsive Type also allows you to set fluid sizes for the line-height and letter-spacing properties. They have the same syntax and work the same way as responsive font sizes.

html {
  line-height: responsive 1.2em 1.8em;
  line-height-range: 420px 1280px;

  /* or extended syntax: */
  line-height: responsive;
  min-line-height: 1.2em;
  max-line-height: 1.8em;
  lower-line-height-range: 420px;
  upper-line-height-range: 1280px;
}
html {
  letter-spacing: responsive 0px 4px;
  letter-spacing-range: 420px 1280px;

  /* or extended syntax: */
  letter-spacing: responsive;
  min-letter-spacing: 0px;
  max-letter-spacing: 4px;
  lower-letter-spacing-range: 420px;
  upper-letter-spacing-range: 1280px;
}

Note: Unitless line heights are not supported.

Defaults

To get started you only need to specify the responsive property, all other values have sane defaults.

font-size
  • min-font-size: 14px

  • max-font-size: 21px

  • lower-font-range: 420px

  • upper-font-range: 1280px

line-height
  • min-line-height: 1.2em

  • max-line-height: 1.8em

  • lower-line-height-range: 420px

  • upper-line-height-range: 1280px

letter-spacing
  • min-letter-spacing: 0px

  • max-letter-spacing: 4px

  • lower-letter-spacing-range: 420px

  • upper-letter-spacing-range: 1280px

Browser Support

postcss-responsive-type just uses calc, vw units, and media queries behind the scenes, so it works on all modern browsers (IE9+). Although Opera Mini is not supported.

Legacy browsers will ignore the output responsive font-size. You can easily provide a simple static fallback:

.foo {
  font-size: 16px;
  font-size: responsive;
}

MIT Β© Sean King

More Repositories

1

rucksack

A little bag of CSS superpowers, built on PostCSS
JavaScript
1,849
star
2

poststylus

PostCSS adapter for Stylus
JavaScript
285
star
3

postcss-hexrgba

PostCSS plugin that adds shorthand hex methods to rgba() values
JavaScript
70
star
4

postcss-fontpath

PostCSS plugin to automatically generate font-face src sets based on a path to font files
JavaScript
55
star
5

postcss-alias

PostCSS plugin that allows you to create aliases for CSS properties
JavaScript
47
star
6

postcss-clearfix

PostCSS plugin that adds a 'fix' argument to the 'clear' property
JavaScript
47
star
7

wordprismic

Utility to import existing Wordpress blogs into the Prismic.io content platform
JavaScript
31
star
8

postcss-position

PostCSS plugin that adds shorthand declarations for position attributes
JavaScript
25
star
9

laggard

Automatically generate CSS fallbacks for legacy browsers, built on PostCSS
JavaScript
23
star
10

svelte-gallery

Intelligent masonry style photo gallery that maintains image aspect ratios in perfect rows
JavaScript
21
star
11

satchel

The little bag of CSS-in-JS superpowers
TypeScript
16
star
12

postcss-input-style

PostCSS plugin that adds new pseudo-elements for easily styling the inner elements of inputs
JavaScript
16
star
13

react-portal-overlay

Lightweight fullscreen overlays using React portals
TypeScript
13
star
14

generator-web-component

Quickly scaffold powerful web components with Yeoman
JavaScript
12
star
15

postcss-subgrid

PostCSS plugin that shims some basic behaviour of the proposed CSS subgrid spec
JavaScript
10
star
16

svelte-meta

Easily generate SEO metadata for Svelte
Svelte
10
star
17

juli-cli

CLI tool to generate native web apps using Juli
Shell
4
star
18

svelte-imgix

Svelte action for responsive, lazily-loaded images with Imgix
TypeScript
4
star
19

lazy-import

Declaratively import HTML components when you're ready to use them
HTML
3
star
20

prismic-apollo-introspect

Prismic introspection utility for generating fragment types for Apollo
JavaScript
3
star
21

svelte-hamburger

Animated hamburger icon for svelte
Svelte
3
star
22

the-marketer

In a world overrun with angry consumers, only one person can save us
GDScript
3
star
23

gatsby-boilerplate

Opinionated and configurable boilerplate to quickly scaffold progressive, lightweight Gatsby projects
TypeScript
2
star
24

rucksackcss.org

Website for Rucksack
CSS
2
star
25

satchel-docs

Satchel's documentation, hosted by Gitbook
1
star
26

react-hamburger-icon

Featherweight animated hamburger icon for React
TypeScript
1
star
27

svelte-boilerplate

Boilerplate for modern distributable svelte components
TypeScript
1
star
28

gatsby-plugin-notify

Gatsby plugin that adds system notifications to your development build
JavaScript
1
star
29

react-component-boilerplate

Lightweight boilerplate for scaffolding modern React components
JavaScript
1
star