Conversión de unidades CSS
Consulta y convierte unidades CSS — px, em, rem, %, vw, vh, vmin, vmax, ch, ex, lh, rlh, cm, mm, in, pt, pc, q, deg, rad, turn, s, ms, dpi, dpcm, dppx y fr — usando tus tamaños de fuente raíz y del elemento padre, y marca qué resultados dependen del contexto.
Se ejecuta en tu navegadorTodos los cálculos se hacen en tu navegador; tus datos no salen de este dispositivo.
Convertir
Contexto de conversión
em y % necesitan el tamaño de fuente del elemento padre, rem y rlh el tamaño de fuente raíz, vw / vh el tamaño del viewport, ch / ex las métricas de la fuente y lh la altura de línea. Las conversiones entre unidades absolutas (px / in / cm / mm / q / pt / pc) no dependen de nada de eso.
Resultado
| Unidad | Valor | Nota |
|---|---|---|
| px | 16 | Independiente del contexto |
| in | 0.166667 | Independiente del contexto |
| cm | 0.423333 | Independiente del contexto |
| mm | 4.233333 | Independiente del contexto |
| q | 16.933333 | Independiente del contexto |
| pt | 12 | Independiente del contexto |
| pc | 1 | Independiente del contexto |
| em | 0.8 | Depende del contexto |
| rem | 1 | Depende del contexto |
| % | 80 | Depende del contexto |
| vw | 1.25 | Depende del contexto |
| vh | 2.222222 | Depende del contexto |
| vmin | 2.222222 | Depende del contexto |
| vmax | 1.25 | Depende del contexto |
| ch | 1.6 | Depende del contexto |
| ex | 1.6 | Depende del contexto |
| lh | 0.533333 | Depende del contexto |
| rlh | 0.666667 | Depende del contexto |
Referencia de unidades
| Unidad | Dimensión | Nota | Depende de |
|---|---|---|---|
| px | Longitud | Pixel · The CSS pixel: the spec fixes 1in = 96px, which anchors every other length conversion. | Nada (unidad absoluta) |
| in | Longitud | Inch · 1in = 96px = 2.54cm. | Nada (unidad absoluta) |
| cm | Longitud | Centimetre · 1cm = 96/2.54px ≈ 37.7953px. | Nada (unidad absoluta) |
| mm | Longitud | Millimetre · 1mm = 1/10cm ≈ 3.7795px. | Nada (unidad absoluta) |
| q | Longitud | Quarter-millimetre · 1Q = 1/40cm ≈ 0.9449px, mostly used in print-oriented CSS. | Nada (unidad absoluta) |
| pt | Longitud | Point · 1pt = 1/72in = 96/72px ≈ 1.3333px; on screen it is unrelated to printer points. | Nada (unidad absoluta) |
| pc | Longitud | Pica · 1pc = 12pt = 16px. | Nada (unidad absoluta) |
| em | Longitud | Relative to parent font size · 1em is the inherited font-size of the element. On font-size it is relative to the parent, on margin to the element itself — which is why em compounds. | Tamaño de fuente del padre |
| rem | Longitud | Relative to root font size · 1rem is the font-size of the root element (html), 16px by default, and never compounds through the tree. | Tamaño de fuente raíz |
| % | Longitud | Percentage · A percentage resolves against the parent’s same property: font-size against the parent font size, width against the parent width — so 50% means different things per property. | Tamaño de fuente del padre |
| vw | Longitud | 1% of viewport width · 1vw = viewport width ÷ 100, and it changes when a scrollbar appears. | Tamaño del viewport |
| vh | Longitud | 1% of viewport height · 1vh = viewport height ÷ 100; on mobile the toolbar changes that height while scrolling — see the viewport units tool. | Tamaño del viewport |
| vmin | Longitud | 1% of the smaller viewport side · 1vmin = min(viewport width, height) ÷ 100, which stays stable across orientation changes. | Tamaño del viewport |
| vmax | Longitud | 1% of the larger viewport side · 1vmax = max(viewport width, height) ÷ 100. | Tamaño del viewport |
| ch | Longitud | Width of the “0” glyph · 1ch is the advance width of “0” in the current font, handy for limiting line length; it depends on the font and is often approximated as half the font size. | Métricas de la fuente (ancho de avance / altura x) |
| ex | Longitud | x-height · 1ex is the font’s x-height, usually about half the font size and very font-dependent. | Métricas de la fuente (ancho de avance / altura x) |
| lh | Longitud | Current line height · 1lh equals the element’s computed line-height, which makes line-aligned spacing trivial. | Altura de línea |
| rlh | Longitud | Root line height · 1rlh equals the root element’s line-height and ignores the current element. | Tamaño de fuente raíz, Altura de línea |
| deg | Ángulo | Degree · A full circle is 360deg; the most common angle in transforms and gradients. | Nada (unidad absoluta) |
| rad | Ángulo | Radian · A full circle is 2π rad ≈ 6.2832rad, so 1rad = 180/π deg ≈ 57.2958deg. | Nada (unidad absoluta) |
| turn | Ángulo | Turn · 1turn = 360deg, the clearest way to write a full rotation. | Nada (unidad absoluta) |
| s | Tiempo | Second · 1s = 1000ms, the default unit for transitions and animations. | Nada (unidad absoluta) |
| ms | Tiempo | Millisecond · 1ms = 0.001s. | Nada (unidad absoluta) |
| dpi | Resolución | Dots per inch · 1dpi = 1/2.54 dpcm and 1dppx = 96dpi; prefer dppx in media queries. | Nada (unidad absoluta) |
| dpcm | Resolución | Dots per centimetre · 1dpcm = 2.54/96 dppx ≈ 0.0265dppx. | Nada (unidad absoluta) |
| dppx | Resolución | Dots per pixel · The device pixel ratio: 1dppx = 96dpi, and Retina displays are usually 2dppx. | Nada (unidad absoluta) |
| fr | Fracción flexible | Fraction of free grid space · fr only exists inside grid track sizing, where it splits the free space proportionally; it cannot be converted to any length. | Nada (unidad absoluta) |
Qué hace esta herramienta
- Convierte los px de un diseño a rem / em: introduce el tamaño de fuente raíz y del padre y lee directamente 16px = 1rem o 16px = 0.8em (padre 20px).
- Calcula el valor en vw antes de escribir tipografía fluida: con una ventana de 1280px, 16px son 1.25vw, sin hacer cálculos mentales con porcentajes.
- Consulta qué significa realmente cada unidad: cuánto mide ch, cuándo ayudan ex y lh, cuántos px es 1Q, cómo se relacionan dpcm y dppx; la referencia indica las dependencias.
- Depura problemas como „por qué el texto crece al anidarse“: em y % se acumulan respecto al padre, y la herramienta señala exactamente qué resultados dependen del tamaño de fuente del padre.
Ejemplo
Entrada
Valor 16, de px, a rem, con tamaño raíz 16px, tamaño de fuente del padre 20px y ventana de 1280 × 720
Salida
16px = 1rem (Depende de: tamaño de fuente raíz); el mismo valor es 0.8em en em (Depende de: tamaño de fuente del padre), 80% en %, 1.25vw en vw y 0.423333cm en cm (Independiente del contexto)
px y cm son longitudes absolutas, así que esa conversión no tiene dependencia de contexto y se marca como „independiente del contexto“.
Preguntas frecuentes
¿Por qué cada resultado se marca como „dependiente del contexto“?
Solo las longitudes absolutas (px, in, cm, mm, q, pt, pc) tienen valores fijos. em depende del tamaño de fuente del padre, rem del tamaño raíz, % de la propiedad homónima del padre, vw / vh de la ventana, ch / ex de las métricas de fuente y lh / rlh de las alturas de línea. El mismo 2em son distintos píxeles en otro contexto, así que las dependencias se listan junto al valor.
¿Cuál es la diferencia entre em y rem?
rem solo mira el elemento raíz (html), así que nunca se acumula. em mira el tamaño de fuente del elemento actual, y como los tamaños de fuente suelen declararse respecto al padre, los valores em se multiplican por el árbol. Usa rem para espaciados y radios que deban mantenerse estables, y em cuando el valor deba „escalar con el texto“, como alinear un icono con su etiqueta.
¿Son pt, cm e in tamaños físicos reales en pantalla?
No. CSS fija 1in = 96px, así que pt, cm y mm son solo píxeles CSS derivados de esa proporción y no corresponden a longitudes impresas. Para la salida impresa usa @page con mm y deja que el navegador los adapte al dispositivo.
¿Por qué fr no se puede convertir?
fr significa „una parte del espacio sobrante“ y solo existe dentro del dimensionado de pistas de grid. Su valor en píxeles depende de cuánto espacio consuman las demás pistas del mismo grid-template, así que fuera de un diseño no tiene longitud definida: la herramienta se niega a convertirlo.
¿Qué tamaño de ventana debo introducir?
La ventana de diseño que ves realmente al depurar, barra de desplazamiento incluida: 1vw es un uno por ciento de ella. Ten en cuenta que en móvil la barra de direcciones cambia la altura de la ventana al desplazarte, lo que altera el valor en píxeles de vh; svh, lvh y dvh existen justo para eso.
Palabras clave:css unitspx to rempx to emvw vhunit converter