Skip to content
On this page

Rem to px preset

Converts rem to px for all utilities.

Source Code

Installation

bash
pnpm add -D @unocss/preset-rem-to-px
pnpm add -D @unocss/preset-rem-to-px
bash
yarn add -D @unocss/preset-rem-to-px
yarn add -D @unocss/preset-rem-to-px
bash
npm install -D @unocss/preset-rem-to-px
npm install -D @unocss/preset-rem-to-px
ts
// uno.config.ts
import { defineConfig } from 'unocss'
import presetRemToPx from '@unocss/preset-rem-to-px'

export default defineConfig({
  presets: [
    presetRemToPx(),
    // ...other presets
  ],
})
// uno.config.ts
import { defineConfig } from 'unocss'
import presetRemToPx from '@unocss/preset-rem-to-px'

export default defineConfig({
  presets: [
    presetRemToPx(),
    // ...other presets
  ],
})

Usage

html
<div class="m-2"></div>
<div class="m-2"></div>
css
.m-2 {
  margin: 0.5rem;
}
.m-2 {
  margin: 0.5rem;
}
css
.m-2 {
  margin: 8px;
}
.m-2 {
  margin: 8px;
}

Options

baseFontSize

  • Type: number
  • Default: 16

The base font size to convert rem to px (1rem = n px).

Released under the MIT License.