Files
stack/packages/mosaic/framework/skills/unocss/references/preset-rem-to-px.md
fargo 1a822493ba format: apply repo prettier (3.8.1) to the folded skills tree
963 markdown files reformatted with the repository's pinned prettier so
pnpm format:check covers the folded tree like every other repo file.

The formatter's embedded-language pass also normalized code fences
(TS semicolons, closed HTML tags in examples, lowercased CSS hex colors,
one renumbered list that skipped an index). Alphanumeric token deltas vs
the fold commit were audited file-by-file; all are formatter-equivalent
markup normalizations plus the four sanitized skills.
2026-08-19 14:37:17 -05:00

1.6 KiB

name, description
name description
preset-rem-to-px Convert rem units to px for utilities

Preset Rem to Px

Converts rem units to px in generated utilities.

Installation

import { defineConfig, presetRemToPx, presetWind3 } from 'unocss';

export default defineConfig({
  presets: [presetWind3(), presetRemToPx()],
});

What It Does

Transforms all rem values to px:

<div class="p-4"></div>

Without preset:

.p-4 {
  padding: 1rem;
}

With preset:

.p-4 {
  padding: 16px;
}

Use Cases

  • Projects requiring pixel-perfect designs
  • Environments where rem doesn't work well
  • Consistency with pixel-based design systems
  • Email templates (better compatibility)

Options

presetRemToPx({
  // Base font size for conversion (default: 16)
  baseFontSize: 16,
});

Custom base:

presetRemToPx({
  baseFontSize: 14, // 1rem = 14px
});

With Preset Wind4

Note: presetRemToPx is not needed with preset-wind4. Use the built-in processor instead:

import { createRemToPxProcessor } from '@unocss/preset-wind4/utils';

export default defineConfig({
  presets: [
    presetWind4({
      preflights: {
        theme: {
          process: createRemToPxProcessor(),
        },
      },
    }),
  ],
  // Also apply to utilities
  postprocess: [createRemToPxProcessor()],
});

Important Notes

  • Order matters: place after the preset that generates rem values
  • Affects all utilities with rem units
  • Theme values in rem are also converted