Search Tools

CSS relative length conversion

Convert CSS relative lengths using explicitly specified contextual references in px

Enter the reference values required by the units in use. Browser defaults are not inferred.

The percentage reference dimension varies by property and is not determined automatically.

Choose the unit below. Negative values are valid only for margin. Maximum absolute value: 1 billion.

Select a property because it determines negative-value handling and the reference for em and %.

Required when using rem. Enter the resolved root value.

For font-size use the parent's resolved font size; otherwise use the target element's.

Required when using vw. CSS default vw is based on the large viewport.

Required when using vh. It may differ from the currently visible screen height.

Check the property's percentage reference before entering it; for margin/padding this can be the containing block's logical width.

Results

Results update automatically when the required values are entered.

Report an issue

Method, applicability and sources

Calculation method

1 rem = resolved root font-size; 1 em = reference font-size; 1 vw = viewport width ÷ 100; 1 vh = viewport height ÷ 100; 1% = property's reference dimension ÷ 100. Converted value = input length × source-unit px factor ÷ target-unit px factor.

Worked example (hypothetical values)

Example: with a 16 px root font size, 2 rem = 32 px. With a viewport width of 1,000 px, 5 vw = 50 px.

Applicability and limitations

Web authors calculating CSS relative lengths under known layout conditions. Excludes unresolved computed styles, auto, calc(), container units, dynamic viewports, automatic percentage-reference inference, rem on the root's own font-size, and browser rendering or zoom differences.

Method and sources

Method: CSS Values and Units 4 WD 2024-03-12; CSS Box Model 3 REC 2024-04-11 / conversion implementation v1. Data recorded: 2026-11-20.