CSS unit converter
This CSS unit converter turns a numeric length into px, em, rem, or pt using the base font size you provide.
Run — free
It is useful when a design specification, stylesheet, document, or component library uses a different unit from the one your project expects. Enter the value, choose the source and target units, and set the font-size reference in pixels. The converter applies standard CSS pixel and point ratios, uses the same supplied base for relative units, and returns a clean numeric result plus a ready-to-copy CSS value.
Choose the source, target, and reference deliberately
Start by entering the numeric part of the CSS length without its unit, then select the matching source unit. Choose px, em, rem, or pt as the target and provide a positive base font size measured in pixels. The base controls every conversion that enters or leaves em or rem. For example, with a base of 16 pixels, 2rem converts to 32px, while 24px converts to 1.5em. In actual CSS, em commonly refers to the computed font size of the relevant element or its parent, while rem refers to the root element. This tool has one base field, so you should enter the reference appropriate to the value you are converting. When converting em, use the applicable local font size. When converting rem, use the root font size. Conversions involving only px and pt do not mathematically depend on that font reference, but the field remains required so every request has one consistent, explicit contract. Keeping the reference visible also prevents an accidental assumption that every site uses a 16px root.
Understand the conversion path and rounding
The converter normalizes the source value to CSS pixels and then converts those pixels to the requested target. Relative units use the supplied base: an em or rem value is multiplied by the base to obtain pixels, and a pixel value is divided by the base to obtain em or rem. Points use the standard CSS relationship of 96 pixels per inch and 72 points per inch, which means 1pt equals 96 divided by 72 CSS pixels. Routing every supported pair through pixels makes conversions predictable, including pt to rem and em to pt. You can set precision from zero through twelve decimal places. Rounding happens only after the complete conversion, rather than at an intermediate step, so a multi-unit calculation does not accumulate avoidable display error. The response includes the normalized source and target names, the base, the rounded number, and a CSS string such as 1.5rem. If source and target are identical, the same validated value is returned, rounded to the requested precision. Inputs must be finite numbers, and a base of zero or less is rejected.
Use converted values without losing design intent
A correct number is only part of a good CSS migration. Before replacing units across a stylesheet, decide whether the original measurement was meant to scale with typography. Pixels and points are effectively absolute CSS measurements, while em and rem participate in font-relative sizing. Converting a fixed border from px to rem changes how it behaves when users or themes change the root font size; that may be desirable for spacing but surprising for hairline rules. Test converted declarations at the smallest and largest font settings your interface supports, especially for line height, controls, and responsive layouts. For design-system work, record the base used for each batch so future maintainers can reproduce the values. The API is deterministic and has no network, random, or clock dependency, making it suitable for build scripts, code generators, migration checks, and repeatable tests. Unsupported units such as percentages, viewport units, physical centimeters, or mixed expressions are rejected instead of guessed. For calc() expressions, convert each compatible numeric term separately and preserve the expression structure in your stylesheet.
What you can do with it
Migrate a pixel-based component
Convert fixed typography and spacing values to em or rem while documenting the reference font size used by the component.
Match print and web specifications
Translate point measurements from a design or document into CSS pixels, then verify the result at the intended display scale.
Automate design-token generation
Produce deterministic unit variants for a token pipeline, snapshot test, stylesheet generator, or component-library build.
FAQ
How much does a conversion cost?
It runs free in your browser. A successful API request costs $0.002 for one converted item.
What base should I use for rem?
Use the root element's computed font size in pixels. Many projects use 16px, but your stylesheet or user settings may establish a different value.
What base should I use for em?
Use the computed font size that the em measurement is relative to, usually the relevant element or its parent depending on the CSS property and context.
How are points converted?
The calculation uses the CSS reference ratio of 96px per inch and 72pt per inch, so 1pt equals 1.333333 recurring CSS pixels.
Which units are rejected?
Any source or target outside px, em, rem, and pt is rejected as an unsupported unit pair. The converter does not guess percentages, viewport units, or calc() expressions.
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/web/css-unit-convert \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"value":24,"from":"px","to":"rem","base":16}'const res = await fetch("https://api.kit.forhosting.com/web/css-unit-convert", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"value": 24,
"from": "px",
"to": "rem",
"base": 16
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/web/css-unit-convert",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"value": 24,
"from": "px",
"to": "rem",
"base": 16
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/web/css-unit-convert", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"value":24,"from":"px","to":"rem","base":16}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"value":24,"from":"px","to":"rem","base":16}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/web/css-unit-convert", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"value": 24,
"from": "px",
"to": "rem",
"base": 16
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "web.css_unit_convert",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Limits
timeout_sec | 30 |
max_crawl_pages | 25 |
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |