{"id":13674657,"url":"https://github.com/pierreburel/sass-rem","last_synced_at":"2025-05-16T12:09:54.915Z","repository":{"id":9650660,"uuid":"11586603","full_name":"pierreburel/sass-rem","owner":"pierreburel","description":"Sass function and mixin to use rem units with optional pixel fallback.","archived":false,"fork":false,"pushed_at":"2023-11-10T21:13:45.000Z","size":375,"stargazers_count":328,"open_issues_count":0,"forks_count":59,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-02T04:57:17.439Z","etag":null,"topics":["css","rem","sass","scss"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pierreburel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-07-22T16:42:09.000Z","updated_at":"2025-03-15T20:58:45.000Z","dependencies_parsed_at":"2023-11-10T22:34:46.112Z","dependency_job_id":null,"html_url":"https://github.com/pierreburel/sass-rem","commit_stats":{"total_commits":54,"total_committers":6,"mean_commits":9.0,"dds":0.5555555555555556,"last_synced_commit":"8dcd38e95c247e660a3cbe70ec5cbb9d96774938"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pierreburel%2Fsass-rem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pierreburel%2Fsass-rem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pierreburel%2Fsass-rem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pierreburel%2Fsass-rem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pierreburel","download_url":"https://codeload.github.com/pierreburel/sass-rem/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247574088,"owners_count":20960495,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css","rem","sass","scss"],"created_at":"2024-08-02T11:00:56.323Z","updated_at":"2025-04-09T06:09:20.560Z","avatar_url":"https://github.com/pierreburel.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# sass-rem [![Node.js CI](https://github.com/pierreburel/sass-rem/actions/workflows/node.js.yml/badge.svg)](https://github.com/pierreburel/sass-rem/actions/workflows/node.js.yml)\n\nSass function and mixin to use rem units with optional pixel fallback.\n\n## Breaking changes\n\n- **4.0**: changed default function name when imported globally (`@use \"rem\" as *;` or `@import \"sass-rem\";`) to `rem-convert`, as [CSS now use `rem()` for calculating the remainder](https://developer.mozilla.org/en-US/docs/Web/CSS/rem). It shouldn't change anything if you used Sass Modules introduced in 3.0 (`rem.convert`).\n\n- **3.0**: now using [Sass Modules](https://sass-lang.com/blog/the-module-system-is-launched), using `@use` and `rem` is renamed to `rem.convert`. You could still use `@import` with no changes (see usage below), but **if you need LibSass/node-sass and Ruby Sass support (both deprecated), you should stay on 2.0** (which works fine) or use the [PostCSS](https://github.com/pierreburel/postcss-rem) version.\n\n- **2.0**: `$rem-fallback` is now set to `false` ([see support](http://caniuse.com/#feat=rem)) and `$rem-baseline` to `16px` by default.\n\n---\n\n## Installation\n\nInstall with [Yarn](https://yarnpkg.com/) or [npm](https://www.npmjs.com/):\n\n* `yarn add sass-rem`\n* `npm install sass-rem`\n\n---\n\n## Usage\n\nImport in your project depending of your setup:\n\n```scss\n@use \"rem\";\n// or @use \"~sass-rem\" as rem;\n// or @use \"../node_modules/sass-rem\" as rem;\n\n.demo {\n  font-size: rem.convert(24px); // Simple\n  padding: rem.convert(5px 10px); // Multiple values\n  border-bottom: rem.convert(1px solid black); // Multiple mixed values\n  box-shadow: rem.convert(0 0 2px #ccc, inset 0 0 5px #eee); // Comma-separated values\n  // Multiple properties\n  @include rem.convert((\n    margin: 10px 5px,\n    text-shadow: (1px 1px #eee, -1px -1px #eee) // Parentheses needed because of comma\n  ));\n}\n```\n\nWill output:\n\n```css\n.demo {\n  font-size: 1.5rem;\n  padding: 0.3125rem 0.625rem;\n  border-bottom: 0.0625rem solid black;\n  box-shadow: 0 0 0.125rem #ccc, inset 0 0 0.3125rem #eee;\n  margin: 0.625rem 0.3125rem;\n  text-shadow: 0.0625rem 0.0625rem #eee, -0.0625rem -0.0625rem #eee;\n}\n```\n\n---\n\n## Namespace\n\nYou can change the namespace when importing and use `rem` function and mixin instead of `convert`:\n\n```scss\n@use \"rem\" as to; // Because why not?\n\n.demo {\n  font-size: to.rem(24px);\n}\n```\n\nOr you can even load the library globally (but beware of conflicts, avoided by the idea of modules):\n\n```scss\n@use \"rem\" as *;\n\n.demo {\n  font-size: rem-convert(24px);\n}\n```\n\n---\n\n## Using pixel fallback\n\nYou can enable pixel fallback by setting `$fallback` to `true`, but you will have to use the mixin instead of the function. The mixin accepts a map to convert multiple properties at once too:\n\n```scss\n@use \"rem\" with (\n  $fallback: true\n);\n\n.demo {\n  @include rem.convert(font-size, 24px); // Simple\n  @include rem.convert(padding, 5px 10px); // Multiple values\n  @include rem.convert(border-bottom, 1px solid black); // Multiple mixed values\n  @include rem.convert(box-shadow, 0 0 2px #ccc, inset 0 0 5px #eee); // Comma-separated values\n  // Multiple properties\n  @include rem.convert((\n    margin: 10px 5px,\n    text-shadow: (1px 1px #eee, -1px -1px #eee) // Parentheses needed because of comma\n  ));\n}\n```\n\nWill output:\n\n```css\n.demo {\n  font-size: 24px;\n  font-size: 1.5rem;\n  padding: 5px 10px;\n  padding: 0.3125rem 0.625rem;\n  border-bottom: 1px solid black;\n  border-bottom: 0.0625rem solid black;\n  box-shadow: 0 0 2px #ccc, inset 0 0 5px #eee;\n  box-shadow: 0 0 0.125rem #ccc, inset 0 0 0.3125rem #eee;\n  margin: 10px 5px;\n  margin: 0.625rem 0.3125rem;\n  text-shadow: 1px 1px #eee, -1px -1px #eee;\n  text-shadow: 0.0625rem 0.0625rem #eee, -0.0625rem -0.0625rem #eee;\n}\n```\n\n---\n\nYou can totally disable rem units by setting `$px-only` to `true` (for a lt-ie9 only stylesheet for example):\n\n```css\n.demo {\n  font-size: 24px;\n  padding: 5px 10px;\n  border-bottom: 1px solid black;\n  box-shadow: 0 0 2px #ccc, inset 0 0 5px #eee;\n  margin: 10px;\n  text-shadow: 1px 1px #eee, -1px -1px #eee;\n}\n```\n\n---\n\n## Changing baseline\n\nBy default, sass-rem now uses a 16px baseline, but you can change this value with `$baseline` and by using the `baseline` mixin on the html element to adjust the root font size. The `rem` function and mixin will calculate rem values accordingly.\nFor example, you can set `$baseline` to 10px to have a root font size of 62.5% and improve readability (10px = 1rem), which was the pre-2.0 behavior:\n\n```scss\n@use \"rem\" with (\n  $baseline: 10px\n);\n\nhtml {\n  @include rem.baseline;\n}\n\n.demo {\n  font-size: rem.convert(24px);\n}\n```\n\nWill output:\n\n```css\nhtml {\n  font-size: 62.5%;\n}\n\n.demo {\n  font-size: 2.4rem;\n}\n```\n\n---\n\nYou can also change the baseline zoom by passing the desired zoom to the `baseline` mixin which will calculate it depending of `$baseline`. Useful for creating responsive typography depending on viewport, especially with a different baseline than 16px:\n\n```scss\n@use \"rem\" with (\n  $baseline: 10px\n);\n\nhtml {\n  @include rem.baseline; // Default zoom to 100%\n\n  @media (max-width: 400px) {\n    @include rem.baseline(75%);\n  }\n\n  @media (min-width: 800px) {\n    @include rem.baseline(125%);\n  }\n}\n```\n\nWill output:\n\n```css\nhtml {\n  font-size: 62.5%;\n}\n\n@media (max-width: 400px) {\n  html {\n    font-size: 46.875%;\n  }\n}\n\n@media (min-width: 800px) {\n  html {\n    font-size: 78.125%;\n  }\n}\n```\n\n## Legacy import\n\nIf you don't want to use Sass Modules, you can still use `@import` with `rem-convert` function, mixin and namespaced `$rem-*` variables:\n\n```scss\n@import \"sass-rem\";\n// or @import \"~sass-rem\";\n// or @import \"../node_modules/sass-rem\";\n\n$rem-baseline: 10px;\n\n.demo {\n  font-size: rem-convert(24px);\n}\n```\n\n---\n\n## See also\n\n- PostCSS version: https://github.com/pierreburel/postcss-rem\n- JavaScript version: https://github.com/pierreburel/startijenn-rem\n- `sass-em` https://github.com/pierreburel/sass-em\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpierreburel%2Fsass-rem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpierreburel%2Fsass-rem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpierreburel%2Fsass-rem/lists"}