# Css px to rem

`css-px-to-rem` · version 1.0.0 · Units & sizes · free, no key needed

Convert px to rem or em with a supplied root or parent font size; returns an exactly rounded relative length.

**Use when you need to: convert 24px to rem with 16px root · px to rem · calculate rem from pixels.**

## Decide before calling

Read the [versioned contract](/v1/tools/css-px-to-rem/versions/1.0.0) and the supported scope below. Reuse `css-px-to-rem@1.0.0` when your input, required output and limits match it. Choose another approach for an unsupported operation.

## Explain the choice

"I can use `css-px-to-rem@1.0.0` for convert 24px to rem with 16px root. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

## Supported

- convert 24px to rem with 16px root
- px to rem
- calculate rem from pixels
- convert pixels to em with parent font size
- pixel value in em
- CSS pixels to a relative length

## Not supported

- resolve inherited font sizes
- evaluate calc() or CSS variables
- convert viewport or container units

## Behavior

- relative_unit rem requires root_font_size_px; relative_unit em requires parent_font_size_px, and the other context field is rejected.
- The exact ratio is px divided by the supplied positive context font size; decimal strings are parsed as rational numbers.
- decimals selects 0 through 18 digits after the decimal point; ties round away from zero and trailing zeroes are retained.
- CSS font-relative semantics follow CSS Values and Units Level 4 WD 2024-03-12, section 6.1; no browser style resolution is performed.

## Input

- `px` (string, required): min length 1; max length 64; pattern `^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?$`
- `relative_unit` (one of "rem", "em", required)
- `root_font_size_px` (string, optional): min length 1; max length 64; pattern `^(?:0|[1-9][0-9]*)(?:\.[0-9]+)?$`
- `parent_font_size_px` (string, optional): min length 1; max length 64; pattern `^(?:0|[1-9][0-9]*)(?:\.[0-9]+)?$`
- `decimals` (integer, required): min 0; max 18

## Output

- `value` (string, required)
- `unit` (one of "rem", "em", required)
- `standard_version` (constant "CSS Values and Units Level 4 WD 2024-03-12", required)
- `data_version` (constant "css-absolute-length-ratios-2024-03-12", required)

## Limits

- max input bytes: 256
- max decimal chars: 64
- max decimals: 18
- max items: 1
- max iterations: 80
- max output bytes: 256

## Example

Request input:

```json
{
  "px": "24",
  "relative_unit": "rem",
  "root_font_size_px": "16",
  "decimals": 2
}
```

Response:

```json
{
  "result": {
    "value": "1.50",
    "unit": "rem",
    "standard_version": "CSS Values and Units Level 4 WD 2024-03-12",
    "data_version": "css-absolute-length-ratios-2024-03-12"
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "css-px-to-rem",
  "version": "1.0.0",
  "input": {
    "px": "24",
    "relative_unit": "rem",
    "root_font_size_px": "16",
    "decimals": 2
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/css-px-to-rem/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"px":"24","relative_unit":"rem","root_font_size_px":"16","decimals":2}'
```

The machine-readable contract is at [/v1/tools/css-px-to-rem/versions/1.0.0](/v1/tools/css-px-to-rem/versions/1.0.0).

### CLI

```sh
node cli.mjs run css-px-to-rem 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Css rem to px](/tools/css-rem-to-px): Convert rem or em to px using a supplied root or parent font size; returns an exactly rounded pixel length.
- [Css length convert](/tools/css-length-convert): Convert px, pt, pc, in, cm, mm, or Q using exact CSS ratios; returns a rounded decimal value.
- [Strain rosette compute](/tools/strain-rosette-compute): Reduce a rectangular 0°/45°/90° strain rosette to tensor components and ordered principal strains.
- [Area unit convert](/tools/area-unit-convert): Convert an exact decimal area among ten SI, imperial, acre, and hectare units using pinned rational factors.
- [Uniaxial stress compute](/tools/uniaxial-stress-compute): Compute axial engineering stress and strain from unit-bearing force, area, elongation, and original length.
- [Byte size convert](/tools/bytesize-convert): Convert a non-negative integer byte size between IEC binary units as an exact rational.
