responsive-scale-mixins
v2.4.1
Published
π¨ SCSS mixins for perfect responsive design with universal browser compatibility. Supports ALL CSS units (px, rem, em, vw, vh, %, etc.) with pixel-perfect scaling and automatic static fallbacks for older browsers. Zero manual calculations - just flawless
Maintainers
Keywords
Readme
π Responsive Scale Mixins
The Future of Responsive Design is Here
Stop wrestling with breakpoints. Start designing once, deploy everywhere.
Imagine building a beautiful UI in Figma, then seeing it perfectly scale on every screen size - from tiny phones (320px) to ultra-wide monitors (9999px) - without writing a single media query. That's the power of Responsive Scale Mixins.
π₯ Why Developers Love It
π― Pixel-Perfect Figma Translation
- Your Figma designs become reality, not approximations
- Zero guessing, zero manual calculations
- What you see in design tools is what users see on any device
β‘ Revolutionary Simplicity
// Before: 50+ lines of media queries
.hero-title {
font-size: 48px;
@media (max-width: 768px) {
font-size: 32px;
}
@media (max-width: 480px) {
font-size: 24px;
}
// ... and so on for every element
}
// After: 1 line that works everywhere
.hero-title {
@include rsm.responsive-scale(font-size, 48, 24);
}π¨ Universal Unit Support
- px, rem, em, vw, vh, %, cm, mm, in, pt, pc - you name it, we scale it
- Intelligent interpolation between desktop and mobile values
- Perfect scaling from 320px phones to 8K displays
π Framework Agnostic
Works with React, Vue, Angular, Svelte, Next.js, Nuxt, Astro, and vanilla CSS. Your favorite framework + perfect responsive design = β€οΈ
π What's New in v2.4.0
Bounded fluid scaling and one-line configuration.
- β
Clamp bounds: pass
$min/$maxto keep fluid values inside a range -responsive-scale(font-size, 48, 24, $min: 24, $max: 48)emitsclamp(24px, <fluid>, 48px)on every breakpoint. One-sided bounds emitmax()/min(). Verified to survive cssnano (Next.js) and esbuild (Vite) minification unchanged; pre-2020 browsers simply keep the static fallback. - β
Breakpoint map configuration:
@use ... with ($rsm-breakpoints: (desktop: 1440px, mobile: 375px))as a one-line alternative to the three individual width variables. - β
breakpoints()function: read the effective design widths to align your own media queries. - β
Live demo: fluid-scaling showcase deployable to GitHub Pages
(
docs/demo/).
π What's New in v2.3.0
Design widths are now real module configuration - and the math is finally continuous.
- β
Breakpoints that actually follow your widths: set
$rsm-desktop-width/$rsm-mobile-widthvia Sass module configuration and BOTH thecalc()expressions and the media-query breakpoints follow - in every compiled stylesheet, regardless of file or load order. Previously, widths set fromglobals.scsssilently failed to reach components compiled separately, and the only workaround was editing the package source. - β
Continuous interpolation: the tablet formula was mathematically broken
since v1 (it multiplied the interpolated value by
100vw / tablet-width), inflating mid-range values (~70px on a 1366px laptop for a 48px design) with 2-2.5x jumps at the breakpoint boundaries. The new curve is exactly the linear blend between your mobile and desktop design values. - β
Stronger CSS output: no CSS variables, no division-by-a-length
(unsupported before 2023 and mangled into invalid CSS by current Dart
Sass). px-style values are emitted as pure vw lengths that scale even in
browsers without
calc()support. Fluid declarations stay wrapped in@supportsbecause production minifiers (cssnano in Next.js/CRA) would otherwise prune the static fallback pair - verified in real Next.js and Vite builds. - β
Zero-config requirement:
responsive-scale-variables()is now optional. - β Clear validation errors instead of silently invalid CSS.
See CHANGELOG.md for the full list and migration notes.
π± How the Breakpoints Work
The design widths define a curve that is continuous at every breakpoint:
| Range | Rule |
| --- | --- |
| viewport β€ mobile-width β 1 | mobile-value Γ viewport / mobile-width |
| mobile-width β¦ desktop-width β 1 | linear blend from mobile-value to desktop-value |
| viewport β₯ desktop-width | desktop-value Γ viewport / desktop-width |
With the default widths (desktop 1920px, mobile 390px), a
responsive-scale(font-size, 48, 24) renders:
| Viewport | Rendered size | | --- | --- | | 390px | 24px (mobile design value) | | 768px | β29.9px | | 1366px | β39.3px | | 1919px | β47.9px | | 1920px | 48px (desktop design value) |
No jumps, no inflation - exactly the proportions you designed.
βοΈ Configuring Your Design Widths
This is the single most important section. The breakpoints are derived from
three module variables (defaults: desktop 1920px, tablet 768px, mobile
390px):
| Variable | Meaning |
| --- | --- |
| $rsm-desktop-width | Design canvas width for desktop (e.g. your Figma frame) |
| $rsm-tablet-width | Legacy - only feeds --computed-tablet-scale-factor |
| $rsm-mobile-width | Design canvas width for mobile |
Option A (recommended): @use ... with (...)
Individual width variables:
// Any stylesheet that needs the mixins
@use "responsive-scale-mixins" as rsm with (
$rsm-desktop-width: 1440px,
$rsm-tablet-width: 768px,
$rsm-mobile-width: 375px
);
.my-element {
@include rsm.responsive-scale(font-size, 48, 24);
}...or the equivalent one-map form (v2.4):
@use "responsive-scale-mixins" as rsm with (
$rsm-breakpoints: (desktop: 1440px, tablet: 768px, mobile: 375px)
);desktop and mobile are required, tablet is optional. The two forms are
mutually exclusive - mixing them fails with a clear error.
Module configuration is applied when the module is loaded, so it works regardless of rule order and reaches every stylesheet compiled with that configuration.
Recommended pattern for real projects - create one project-owned wrapper file and import it everywhere:
// styles/_rsm.scss (your file, lives in your repo)
@use "responsive-scale-mixins" as rsm with (
$rsm-desktop-width: 1440px,
$rsm-mobile-width: 375px
);
@forward "responsive-scale-mixins";// any component / page stylesheet
@use "../styles/rsm" as rsm;
.card {
@include rsm.responsive-scale(padding, 32 48, 16 24);
}Because every compilation unit loads your wrapper, the configured widths are guaranteed - even in build tools that compile each stylesheet separately (Next.js CSS Modules, Angular component styles, Vite, ...).
β οΈ Sass can configure a module only once per compilation, and only at its first load. Configure it in your wrapper (or entry) file - not twice.
Option B: responsive-scale-variables() mixin (legacy, single-compile builds)
@use "responsive-scale-mixins" as rsm;
:root {
// Must run BEFORE any responsive-scale() include in the same compilation
@include rsm.responsive-scale-variables(1440px, 768px, 375px);
}Since v2.3.0 this mixin is optional - the scaling mixins no longer depend on CSS variables. It still:
- emits the legacy custom properties (
--computed-scale-factorand friends) for hand-written styles that reference them; - sets the fallback flag / widths at runtime - but
!globalmutation only affects the current compilation unit and only forresponsive-scale()includes that come after it. That is precisely why widths set this way never reached separately-compiled components in v2.2.x and earlier.
Option C: legacy @import (old builds)
// Set the variables BEFORE the import - the classic !default override pattern
$rsm-desktop-width: 1440px;
$rsm-mobile-width: 375px;
@import "responsive-scale-mixins";
.my-element {
@include responsive-scale(font-size, 48, 24);
}π Quick Start
Installation
npm install responsive-scale-mixins
# or: yarn add responsive-scale-mixins
# or: pnpm add responsive-scale-mixinsMinimal usage (no global setup required)
@use "responsive-scale-mixins" as rsm;
.hero-title {
@include rsm.responsive-scale(font-size, 48, 24);
}Framework-Specific Setup
Next.js (App Router & Pages Router)
// app/globals.scss (or styles/globals.scss)
@use "responsive-scale-mixins" as rsm;
:root {
// Optional: emit the legacy CSS variables for custom styles
@include rsm.responsive-scale-variables();
}Components compiled as CSS Modules load their own copy of the module. Add the
configuration to every compilation via sassOptions:
// next.config.js
module.exports = {
sassOptions: {
additionalData: `@use "responsive-scale-mixins" as rsm with (
$rsm-desktop-width: 1440px,
$rsm-mobile-width: 375px
);`,
},
};β οΈ Pick ONE configuration channel.
additionalDataprepends the config to every compiled stylesheet, so your own files must NOT configure the module again (@use "responsive-scale-mixins" as rsm;withoutwith (...)is fine - Sass reuses the already-configured module). Configuring twice fails with "This module was already loaded, so it can't be configured using with". If you prefer the wrapper-file pattern, inject@use "styles/rsm" as rsm;viaadditionalDatainstead and drop the injected module config.
Vite (Vue / React / SvelteKit / Astro)
// vite.config.ts
export default {
css: {
preprocessorOptions: {
scss: {
additionalData: `@use "responsive-scale-mixins" as rsm with (
$rsm-desktop-width: 1440px,
$rsm-mobile-width: 375px
);`,
},
},
},
};Create React App
// src/index.scss
@use "responsive-scale-mixins" as rsm with (
$rsm-desktop-width: 1440px,
$rsm-mobile-width: 375px
);
:root {
@include rsm.responsive-scale-variables();
}Angular
Angular compiles component styles separately. Configure once in
src/styles.scss and make the widths available to components with the
wrapper pattern:
// src/_rsm.scss
@use "responsive-scale-mixins" as rsm with (
$rsm-desktop-width: 1440px,
$rsm-mobile-width: 375px
);
@forward "responsive-scale-mixins";// src/styles.scss
@use "./rsm" as rsm;
:root {
@include rsm.responsive-scale-variables();
}// any component.scss
@use "../rsm" as rsm;
.card {
@include rsm.responsive-scale(padding, 32 48, 16 24);
}Vue.js / Nuxt.js
// src/assets/styles/main.scss (registered globally)
@use "responsive-scale-mixins" as rsm with (
$rsm-desktop-width: 1440px,
$rsm-mobile-width: 375px
);
:root {
@include rsm.responsive-scale-variables();
}For scoped component styles, use the wrapper-file pattern or additionalData
(Vite/Nuxt config shown above).
CSS Modules
// styles/global.scss - widths for the whole app
@use "responsive-scale-mixins" as rsm with (
$rsm-desktop-width: 1440px,
$rsm-mobile-width: 375px
);
// styles.module.scss - any module
@use "responsive-scale-mixins" as rsm; // same compilation = same widths
.myClass {
@include rsm.responsive-scale(font-size, 24, 16);
}Modules compiled separately need the wrapper-file pattern or
additionalDatainjection - otherwise they get the default widths.
Tailwind CSS
// styles/main.scss
@use "responsive-scale-mixins" as rsm with (
$rsm-desktop-width: 1440px,
$rsm-mobile-width: 375px
);
.custom-element {
@include rsm.responsive-scale(padding, 20 40, 10 20);
@apply bg-blue-500 text-white; // Tailwind classes still work
}Pure CSS alternative (no Sass)
:root {
--computed-scale-factor: calc(100vw / 1440);
--computed-mobile-scale-factor: calc(100vw / 375);
--tablet-proportion-scale-factor: calc((100vw - 375px) / 1065);
}π API Reference
responsive-scale-variables($desktop-width, $tablet-width, $mobile-width, $enable-fallback)
Optional since v2.3.0. Emits the legacy CSS custom properties and sets the
runtime fallback flag. Parameter defaults follow the module configuration, so
calling it with no arguments never resets your @use with widths.
responsive-scale($property, $desktop-value, $mobile-value, $unit, $is-percentage, $desktop-relative, $mobile-relative, $important, $enable-fallback, $min, $max)
The main responsive scaling mixin.
Parameters:
$property: CSS property name (e.g.font-size,padding)$desktop-value: unitless value at the desktop design width (or a space list for shorthand properties)$mobile-value: unitless value at the mobile design width (must match list-ness/length of$desktop-value)$unit:px(default),rem,em,%,vw,vh,vmin,vmax,pt,cm,mm,in,pc- pass without quotes$is-percentage:trueto treat the value as a percentage of$desktop-relative/$mobile-relative$desktop-relative/$mobile-relative: the base values for percentage mode$important:true, or a string like" !important"$enable-fallback:null(follow the global flag),true, orfalse$min/$max(v2.4): optional unitless bounds (same$unit) applied to every fluid declaration:
// Classic bounded pattern: never smaller than the mobile value,
// never larger than the desktop value
.hero-title {
@include rsm.responsive-scale(font-size, 48, 24, $min: 24, $max: 48);
}
// -> clamp(24px, <fluid>, 48px) on desktop, tablet and mobile branches
// One-sided bounds emit max() / min():
.element {
@include rsm.responsive-scale(padding, 32 48, 16 24, $max: 48);
}
// -> min(48px, <fluid>) on each scaled elementBounds apply to the fluid declarations only - static fallbacks keep the
design values. Bounds share the $unit and cannot be combined with
$is-percentage. On browsers without clamp() support (pre-2020) the
declaration is dropped and the static fallback applies, exactly like every
other fluid form.
Generated CSS (default fallbacks on):
.hero-title {
font-size: 48px; /* static fallback */
}
@supports (font-size: 2.5vw) {
.hero-title {
font-size: 2.5vw; /* fluid - pure vw, works without calc() */
}
}
@media screen and (min-width: 390px) and (max-width: 1919px) {
.hero-title {
font-size: 24px; /* static fallback */
}
@supports (font-size: calc(24px + (100vw - 390px) * 24 / 1530)) {
.hero-title {
font-size: calc(24px + (100vw - 390px) * 24 / 1530); /* continuous interpolation */
}
}
}
@media screen and (max-width: 389px) {
.hero-title {
font-size: 24px; /* static fallback */
}
@supports (font-size: 6.1538461538vw) {
.hero-title {
font-size: 6.1538461538vw; /* fluid */
}
}
}Browsers that cannot parse a fluid declaration keep the static one. The
@supports wrapper is deliberately kept even though the expressions are now
universally valid: production CSS minifiers (cssnano in Next.js/Create React
App) prune earlier same-property declarations for mergeable box properties,
which would otherwise silently delete the static fallback pair. Unit-preserving
values (rem/em/%/vw/vh) emit a same-type-division calc() (e.g.
calc(3rem / 1920px * 100vw)), which is supported by 2023+ browsers and falls
back to the static value elsewhere.
responsive-scale-no-fallback(...)
Same parameters minus $enable-fallback; emits fluid declarations only.
breakpoint($name)
Returns the configured width for "desktop", "tablet" or "mobile" - handy
for aligning your own media queries:
@media (min-width: rsm.breakpoint("desktop")) { ... }breakpoints() (v2.4)
Returns the effective design widths as a map (after any $rsm-breakpoints
configuration):
@use "sass:map";
@media (min-width: map.get(rsm.breakpoints(), desktop)) { ... }strip-units($value), scaled-value($val, $width, $unit), tablet-interpolation($desktop-value, $mobile-value, $unit), mobile-scale-expression($mobile-value, $unit)
Utility functions used by the mixins; exposed for advanced use.
π― Examples
Typography
.hero-title {
@include rsm.responsive-scale(font-size, 48, 32);
@include rsm.responsive-scale(line-height, 1.2, 1.3);
@include rsm.responsive-scale(letter-spacing, -1, -0.5);
}Spacing
.card {
@include rsm.responsive-scale(padding, 32 48, 16 24);
@include rsm.responsive-scale(margin-bottom, 24, 16);
}Dimensions
.button {
@include rsm.responsive-scale(width, 200, 150);
@include rsm.responsive-scale(height, 56, 44);
@include rsm.responsive-scale(border-radius, 8, 6);
}Percentage-based Properties
.text {
// Letter-spacing as 1% of font-size
@include rsm.responsive-scale(letter-spacing, 1, 1, px, true, 48, 32);
}REM and EM Units
.element {
@include rsm.responsive-scale(font-size, 3, 2, rem);
@include rsm.responsive-scale(font-size, 2, 1.5, em);
}Bounded (Clamped) Scaling
// Value never shrinks below 24px and never grows above 48px -
// even on ultra-narrow (β€390px) or ultra-wide (β₯1920px) screens
.hero-title {
@include rsm.responsive-scale(font-size, 48, 24, $min: 24, $max: 48);
}Override Specificity
.override-bootstrap {
@include rsm.responsive-scale(font-size, 24, 16, px, false, null, null, true);
}π Browser Support
| Browser | Behavior |
| --- | --- |
| Chrome / Edge / Firefox / Safari (2023+) | Full fluid scaling everywhere (calc() same-type division) |
| Chrome / Edge / Firefox / Safari (2013β2022) | Fluid px scaling; static values for rem/em/%/vh |
| Chrome 79+ / Firefox 75+ / Safari 13.1+ (2020) | $min/$max bounds honored via clamp() / min()/max() |
| Browsers with vw but without calc() (IE9+, viewport units) | Fluid px scaling |
| Very old browsers (no vw) | Static fallback values at each breakpoint |
| IE 11 | Fluid px scaling; static for unit-preserving values and bounds |
Every declaration ships with a static fallback, so nothing is ever blank -
the original Firefox Mobile bug is structurally impossible now that the output
contains no CSS variables, and unsupported fluid forms (including clamp()
bounds on pre-2020 browsers) simply fall back to the static value.
π§ Troubleshooting
"My custom widths from globals.scss don't change the breakpoints"
Sass modules are loaded per compilation unit. A !global mutation (the
v2.2.x responsive-scale-variables() mechanism) only reaches mixin calls in
the same compiled stylesheet, and only if it runs before them. Components
compiled separately (Next.js/Angular/Vite CSS Modules) load a fresh module
with the default widths.
Fix: use Option A (@use ... with (...) + wrapper file or
additionalData injection). That is what it was added for.
"This module was already loaded, so it can't be configured using with"
The module was loaded earlier in the same compilation without configuration. Configure it at the first load - in the wrapper file pattern, the wrapper is always first.
"Compilation error: value must be a unitless number"
v2.3.0 validates inputs. Pass 48 (the unit is the separate $unit
parameter), not 48px.
Import resolution errors ("Can't find stylesheet")
- Ensure v2.3.0+ and the
@use "responsive-scale-mixins" as rsm;syntax - Some bundlers need the package added to their Sass
loadPaths - Legacy fallback:
@import "responsive-scale-mixins";
π Development
npm install
npm test # assertion test suite (test/run-tests.js)The test suite compiles representative stylesheets through the Dart Sass JS API and asserts on the generated CSS, including numeric verification that the interpolation curve is continuous at the breakpoint boundaries.
Manual visual testing:
npx --yes sass test/test.scss test/test.css
# then open test/test.html in a browser and resize the windowSee test/TEST_README.md for details.
Claims registry (marketing figures)
Every number quoted in social/promo material must appear in
docs/claims.json, each entry citing the test or command
that verifies it. Before posting anything: node docs/claims-check.mjs β
all rows must PASS (see MASTER-guide claims discipline).
Live demo
# Local preview
mkdir -p node_modules/responsive-scale-mixins && cp index.scss node_modules/responsive-scale-mixins/index.scss
npx sass --load-path=node_modules docs/demo/demo.scss docs/demo/demo.css
# then open docs/demo/index.html in a browserPushing to main deploys docs/demo/ to GitHub Pages automatically via
.github/workflows/deploy-demo.yml
(one-time setup: Settings β Pages β Source: "GitHub Actions").
Releasing (maintainers)
npm publishing is manual - run npm publish yourself when the tree is
ready (the sanity checklist in AGENTS.md is the pre-flight gate).
GitHub Actions assists with everything else via
.github/workflows/release.yml:
- Bump the version in
package.jsonand theindex.scssheader, updateCHANGELOG.md, commit - Publish manually:
npm publish(use--otp=<code>if 2FA is enabled) - Tag and push:
git tag v2.4.0 && git push origin v2.4.0 - The workflow verifies the tag matches
package.json, runs the test suite, validates the tarball, and creates the GitHub Release
π€ Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Agents contributing to this repository should read AGENTS.md first for architecture invariants and workflow.
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
- Inspired by Figma's responsive design principles
- Built for modern web development workflows
- Compatible with CSS Modules, Styled Components, and traditional CSS
π Support
- π Live Demo: https://sidodus.github.io/responsive-scale-mixins/
- π§ Email: [email protected]
- π Issues: GitHub Issues
- π Docs: Full Documentation
- π¦ NPM: https://www.npmjs.com/package/responsive-scale-mixins
- π€ NPM Profile: https://www.npmjs.com/~sidodus
Made with β€οΈ by Saheed Odulaja
