All Projects → rstacruz → responsive-modular-scale.css

rstacruz / responsive-modular-scale.css

Licence: MIT license
Responsive typography using CSS variables

Projects that are alternatives of or similar to responsive-modular-scale.css

postcss
No description or website provided.
Stars: ✭ 59 (+210.53%)
Mutual labels:  postcss, typography, modular-scale
tailwindcss-fluid-type
A plugin that makes the use of Fluid Type a breeze.
Stars: ✭ 91 (+378.95%)
Mutual labels:  typography, modular-scale
Postcss Interpolate
PostCSS plugin for values interpolation between breakpoints.
Stars: ✭ 9 (-52.63%)
Mutual labels:  postcss, typography
postcss-property-lookup
PostCSS plugin for property lookups, similar to Stylus
Stars: ✭ 67 (+252.63%)
Mutual labels:  postcss
postcss
Add PostCSS to your Svelte project
Stars: ✭ 37 (+94.74%)
Mutual labels:  postcss
harfpy
Python wrapper for HarfBuzz
Stars: ✭ 29 (+52.63%)
Mutual labels:  typography
ekzo
💫 Functional Sass framework for rapid and painless development
Stars: ✭ 32 (+68.42%)
Mutual labels:  typography
sveltekit-starter
Sveltekit starter project created with sveltekit, typescript, tailwindcss, postcss, husky, and storybook. The project has the structure set up for the scaleable web application.
Stars: ✭ 482 (+2436.84%)
Mutual labels:  postcss
python freetype
Python language binding for FreeType library
Stars: ✭ 20 (+5.26%)
Mutual labels:  typography
aerostore
🎨 Aerostore - Aerolab Challenge using Next.js and Micro.js from Zeit
Stars: ✭ 20 (+5.26%)
Mutual labels:  postcss
godlike.css
CSS for layout standardization and usability of web applications
Stars: ✭ 12 (-36.84%)
Mutual labels:  postcss
postcss-hover-media-feature
PostCSS plugin that extracts and wraps rules containing `:hover` pseudo-classes in `@media (hover: hover) {}` media queries
Stars: ✭ 47 (+147.37%)
Mutual labels:  postcss
Gluten
2 Axes/Variable/Super Soft/Display
Stars: ✭ 28 (+47.37%)
Mutual labels:  typography
fdiff
An OpenType table diff tool for fonts. Based on the fontTools TTX format.
Stars: ✭ 33 (+73.68%)
Mutual labels:  typography
postcss-responsive-font
Simple PostCSS plugin for creating responsive font sizes
Stars: ✭ 28 (+47.37%)
Mutual labels:  postcss
theme-ui-native
Build consistent, themeable React Native apps based on constraint-based design principles
Stars: ✭ 67 (+252.63%)
Mutual labels:  typography
postcss-if-media
A PostCSS plugin to inline or nest media queries within CSS rules & properties.
Stars: ✭ 35 (+84.21%)
Mutual labels:  postcss
gulp-reporter
Error report for: CSSLint/EditorConfig/ESLint/HTMLHint/JSCS/JSHint/PostCSS/Standard/TSLint/XO
Stars: ✭ 17 (-10.53%)
Mutual labels:  postcss
postcss-import-url
PostCSS plugin inlines remote files.
Stars: ✭ 47 (+147.37%)
Mutual labels:  postcss
php-typography
A PHP library for improving your web typography.
Stars: ✭ 63 (+231.58%)
Mutual labels:  typography

responsive-modular-scale.css

Responsive typography using CSS variables

This implements a basic Modular Scale system using CSS variables. Use this with postcss-cssnext and postcss-import.

Installation

# using Yarn
yarn add --exact responsive-modular-scale.css

# using npm
npm install --save --save-exact responsive-modular-scale.css

Usage

Simply import it, assuming you're using postcss-import and postcss-cssnext.

@import 'responsive-modular-scale.css';

To use it, use any of the provided --font-size-# custom property sets:

div {
  @apply --font-size-4;
}

This applies a font-size: 2.0736rem declaration for desktops—the default ratio is 1.2, so that's 1rem * 1.2 ^ 4. For mobiles and tablets, it will use a different ratio (1.15 and 1.17 by default).

div { font-size: 1.74901rem; }

@media (min-width: 481px) {
  div { font-size: 1.87389rem; }
}

@media (min-width: 769px) {
  div { font-size: 2.0736rem; }
}

It gives you the following custom property sets:

  • @apply --font-size--1 (negative 1)
  • @apply --font-size-0 (applies to base font size)
  • @apply --font-size-1
  • @apply --font-size-2
  • ... @apply --font-size-20

Configuration

It's recommended you include this in a "common" file included in most of your project's files; usually, that's something like variables.css. You can change these ratios and breakpoints like so:

/* variables.css */
@import 'responsive-modular-scale.css';

:root {
  --ms-ratio-sm: 1.15;
  --ms-ratio-md: 1.17;
  --ms-ratio-lg: 1.2;
  --ms-base: 1rem;
  --ms-base-sm: var(--ms-base);
  --ms-base-md: var(--ms-base-sm);
  --ms-base-lg: var(--ms-base-md);
}

@custom-media --ms-viewport-md (width > 480px);
@custom-media --ms-viewport-lg (width > 768px);
/* your-other-styles.css */
@import './variables.css';

body {
  @apply --font-size-0;
}

div {
  @apply --font-size-4;
}

Prior art

  • postcss-modular-scale is a PostCSS plugin. However, it doesn't support responsive ratios, and the syntax is non-standard CSS.

  • modularscale-sass is, in my opinion, the gold standard modular scale implementation. It only supports Sass, however.

Also see

Thanks

responsive-modular-scale.css © 2019, Rico Sta. Cruz. Released under the MIT License.
Authored and maintained by Rico Sta. Cruz with help from contributors (list).

ricostacruz.com  ·  GitHub @rstacruz  ·  Twitter @rstacruz

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].