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 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:
{
"px": "24",
"relative_unit": "rem",
"root_font_size_px": "16",
"decimals": 2
}
Response:
{
"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), then call execute with:
{
"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)
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.
CLI
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/.
Related 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: Convert px, pt, pc, in, cm, mm, or Q using exact CSS ratios; returns a rounded decimal value.
- Strain rosette compute: Reduce a rectangular 0°/45°/90° strain rosette to tensor components and ordered principal strains.
- Area unit convert: Convert an exact decimal area among ten SI, imperial, acre, and hectare units using pinned rational factors.
- Uniaxial stress compute: Compute axial engineering stress and strain from unit-bearing force, area, elongation, and original length.
- Byte size convert: Convert a non-negative integer byte size between IEC binary units as an exact rational.