Css length convert
css-length-convert · version 1.0.0 · Units & sizes · free, no key needed
Convert px, pt, pc, in, cm, mm, or Q using exact CSS ratios; returns a rounded decimal value.
Use when you need to: convert CSS absolute length units · pixels to inches · convert 96px to 1in.
Decide before calling
Read the versioned contract and the supported scope below. Reuse css-length-convert@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-length-convert@1.0.0 for convert CSS absolute length units. 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 CSS absolute length units
- pixels to inches
- convert 96px to 1in
- points to pixels
- centimeters to CSS pixels
- convert mm to Q
- picas to points
Not supported
- convert rem or em
- convert viewport or container units
- resolve physical device pixels
Behavior
- Uses the CSS reference pixel ratios exactly: 1in = 96px = 72pt = 6pc = 2.54cm = 25.4mm = 101.6Q.
- decimals selects 0 through 18 digits after the decimal point; ties round away from zero and trailing zeroes are retained.
- Absolute-unit ratios follow CSS Values and Units Level 4 WD 2024-03-12, section 6.2; px is the CSS reference pixel, not a hardware pixel.
Input
value(string, required): min length 1; max length 64; pattern^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?$from_unit(one of "px", "pt", "pc", "in", "cm", "mm", "Q", required)to_unit(one of "px", "pt", "pc", "in", "cm", "mm", "Q", required)decimals(integer, required): min 0; max 18
Output
value(string, required)unit(one of "px", "pt", "pc", "in", "cm", "mm", "Q", 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:
{
"value": "96",
"from_unit": "px",
"to_unit": "in",
"decimals": 2
}
Response:
{
"result": {
"value": "1.00",
"unit": "in",
"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-length-convert",
"version": "1.0.0",
"input": {
"value": "96",
"from_unit": "px",
"to_unit": "in",
"decimals": 2
}
}
HTTP (no key)
curl -X POST https://computefirst.net/v1/tools/css-length-convert/versions/1.0.0/execute \
-H "Content-Type: application/json" \
-d '{"value":"96","from_unit":"px","to_unit":"in","decimals":2}'
The machine-readable contract is at /v1/tools/css-length-convert/versions/1.0.0.
CLI
node cli.mjs run css-length-convert 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- Css px to rem: Convert px to rem or em with a supplied root or parent font size; returns an exactly rounded relative length.
- Css rem to px: Convert rem or em to px using a supplied root or parent font size; returns an exactly rounded pixel length.
- Area unit convert: Convert an exact decimal area among ten SI, imperial, acre, and hectare units using pinned rational factors.
- Byte size convert: Convert a non-negative integer byte size between IEC binary units as an exact rational.
- Length convert: Convert a canonical integer length between exact SI and international customary units.
- Pressure unit convert: Convert exact decimal pressure values among seven units and return a reduced exact fraction.