Convert px to rem or em from an AI agent
You need a CSS length in px turned into rem or em for a given font size, rounded to a set number of decimals.
Use css-px-to-rem@1.0.0. It is free and needs no key or sign-up. Convert px to rem or em with a supplied root or parent font size; returns an exactly rounded relative length.
Why call a tool for this
The font size the conversion depends on is part of the call, so the assumption is visible. For example, 24 px with a root font size of 16 px and 2 decimals returns 1.50 rem.
Call it over HTTP
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}'
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"
}
}
Call it over 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
}
}
Check the result
For rem pass root_font_size_px; for em pass parent_font_size_px. Passing the wrong one is rejected as invalid_input. Browsers often use 16 px as the default root size, but check what the site actually sets. To go the other way, use css-rem-to-px.
Full contract, limits and unsupported cases: Css px to rem.