Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Configure and use UnoCSS atomic CSS engine with presets like Wind (Tailwind-compatible), Icons, and Attributify.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/preset-rem-to-px.md
1---2name: preset-rem-to-px3description: Convert rem units to px for utilities4---56# Preset Rem to Px78Converts `rem` units to `px` in generated utilities.910## Installation1112```ts13import { defineConfig, presetRemToPx, presetWind3 } from 'unocss'1415export default defineConfig({16presets: [17presetWind3(),18presetRemToPx(),19],20})21```2223## What It Does2425Transforms all rem values to px:2627```html28<div class="p-4">29```3031Without preset:32```css33.p-4 { padding: 1rem; }34```3536With preset:37```css38.p-4 { padding: 16px; }39```4041## Use Cases4243- Projects requiring pixel-perfect designs44- Environments where rem doesn't work well45- Consistency with pixel-based design systems46- Email templates (better compatibility)4748## Options4950```ts51presetRemToPx({52// Base font size for conversion (default: 16)53baseFontSize: 16,54})55```5657Custom base:5859```ts60presetRemToPx({61baseFontSize: 14, // 1rem = 14px62})63```6465## With Preset Wind46667**Note:** `presetRemToPx` is not needed with `preset-wind4`. Use the built-in processor instead:6869```ts70import { createRemToPxProcessor } from '@unocss/preset-wind4/utils'7172export default defineConfig({73presets: [74presetWind4({75preflights: {76theme: {77process: createRemToPxProcessor(),78}79},80}),81],82// Also apply to utilities83postprocess: [createRemToPxProcessor()],84})85```8687## Important Notes8889- Order matters: place after the preset that generates rem values90- Affects all utilities with rem units91- Theme values in rem are also converted9293<!--94Source references:95- https://unocss.dev/presets/rem-to-px96- https://unocss.dev/presets/wind497-->98