CSS Unit Converter
Convert CSS units instantly — px, rem, em, pt, %, vw, vh
Convert between CSS units (px, rem, em, pt, %, vw, vh) instantly. Enter a value and base font size to get accurate conversions for your web projects.
Convert between CSS units (px, rem, em, pt, %, vw, vh) instantly. Enter a value and base font size to get accurate conversions for your web projects.
Converting CSS units is straightforward:
CSS uses both absolute and relative units. Pixels (px) are fixed-size units. Relative units like rem and em scale based on font sizes. Viewport units (vw, vh) scale based on screen size. Understanding these relationships is key to building responsive designs.
Use rem for most layout sizing (consistent across the page). Use em for component-relative sizing (scales with parent font). Use px for borders and shadows where you need exact control. Use viewport units (vw/vh) for fully responsive elements.
CSS units define the size of visual elements on a webpage. They fall into two categories: absolute units (px, pt, cm, mm, in) which represent fixed physical measurements, and relative units (rem, em, %, vw, vh, vmin, vmax) which scale based on context. The choice of unit significantly impacts how responsive and accessible your design will be. For example, using rem instead of px ensures that text scales properly when users adjust their browser's default font size, improving accessibility. Modern CSS best practices recommend using rem for most sizing needs because it provides consistent scaling throughout the entire document, unlike em which can compound when nested.
The rem (root em) unit is always relative to the root element's font size (html), typically 16px by default. So 1rem = 16px in most browsers. The em unit, however, is relative to the parent element's font size. This means em values can compound in nested elements — if a parent has font-size: 1.2em and a child is set to 1em, the child is actually 1.2em relative to the parent. This compounding effect makes em useful for component-level scaling but potentially confusing for global layout. As a rule of thumb: use rem for predictable, document-wide sizing, and em when you want elements to scale proportionally within their container.
Viewport units (vw, vh, vmin, vmax) are relative to the browser window size. 1vw equals 1% of the viewport width, and 1vh equals 1% of the viewport height. These units enable truly fluid layouts that adapt to any screen size. For example, setting font-size: 5vw creates text that scales proportionally with the viewport. However, viewport units should be used carefully — text sized purely in vw can become too small on mobile or too large on desktop. Combine them with clamp() for responsive typography: font-size: clamp(1rem, 2.5vw, 2rem) ensures text stays between 1rem and 2rem regardless of viewport size.
Most browsers use 16px as the default font size for the root element. This means 1rem = 16px by default. Users can change this in their browser settings, which is why using relative units like rem improves accessibility — your design will respect user preferences.
If the user has changed their browser's default font size (for accessibility reasons), 1rem will reflect that new base size. Additionally, some websites explicitly set a different font-size on the html element (e.g., html { font-size: 10px }), making 1rem = 10px on that site. Our converter uses the standard 16px default, but actual rendered sizes may vary based on the website's styles.
Use em when you want an element to scale relative to its parent's font size. This is particularly useful for padding, margins, and border-radius within components. For example, padding: 1em ensures spacing scales with the text size inside a card component. Use rem for global layout properties like font-size, width, and height where you want consistent sizing across the document.
Divide the pixel value by the base font size. Formula: rem = px ÷ base-font-size. For example, 24px with a 16px base = 24 ÷ 16 = 1.5rem. With our converter, you simply enter 24, select px as the source unit, and the rem value appears automatically.
Viewport units (vw, vh, vmin, vmax) are supported in all modern browsers including Chrome, Firefox, Safari, Edge, and mobile browsers. They've been part of CSS since CSS3 and are widely used in responsive design. For older browser support (IE11), you may need fallbacks using pixel values.