Skip to content
UniKit

CSS 単位換算

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 / fr をルートと親のフォントサイズで換算し、前提に依存する結果にはその旨を示します。

ブラウザ内で動作計算はすべてブラウザ内で行われ、データが端末の外に出ることはありません。

換算

換算の前提

em と % は親のフォントサイズ、rem と rlh はルートのフォントサイズ、vw / vh はビューポートのサイズ、ch / ex はフォントメトリクス、lh は行の高さに依存します。絶対単位(px / in / cm / mm / q / pt / pc)同士の換算は前提に依存しません。

結果

換算結果1rem
基準値:16px前提に依存依存先:ルートのフォントサイズ
単位値説明
px16前提に依存しない
in0.166667前提に依存しない
cm0.423333前提に依存しない
mm4.233333前提に依存しない
q16.933333前提に依存しない
pt12前提に依存しない
pc1前提に依存しない
em0.8前提に依存
rem1前提に依存
%80前提に依存
vw1.25前提に依存
vh2.222222前提に依存
vmin2.222222前提に依存
vmax1.25前提に依存
ch1.6前提に依存
ex1.6前提に依存
lh0.533333前提に依存
rlh0.666667前提に依存

単位リファレンス

単位次元説明依存先
px長さPixel · The CSS pixel: the spec fixes 1in = 96px, which anchors every other length conversion.なし(絶対単位)
in長さInch · 1in = 96px = 2.54cm.なし(絶対単位)
cm長さCentimetre · 1cm = 96/2.54px ≈ 37.7953px.なし(絶対単位)
mm長さMillimetre · 1mm = 1/10cm ≈ 3.7795px.なし(絶対単位)
q長さQuarter-millimetre · 1Q = 1/40cm ≈ 0.9449px, mostly used in print-oriented CSS.なし(絶対単位)
pt長さPoint · 1pt = 1/72in = 96/72px ≈ 1.3333px; on screen it is unrelated to printer points.なし(絶対単位)
pc長さPica · 1pc = 12pt = 16px.なし(絶対単位)
em長さ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.親のフォントサイズ
rem長さRelative to root font size · 1rem is the font-size of the root element (html), 16px by default, and never compounds through the tree.ルートのフォントサイズ
%長さ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.親のフォントサイズ
vw長さ1% of viewport width · 1vw = viewport width ÷ 100, and it changes when a scrollbar appears.ビューポートのサイズ
vh長さ1% of viewport height · 1vh = viewport height ÷ 100; on mobile the toolbar changes that height while scrolling — see the viewport units tool.ビューポートのサイズ
vmin長さ1% of the smaller viewport side · 1vmin = min(viewport width, height) ÷ 100, which stays stable across orientation changes.ビューポートのサイズ
vmax長さ1% of the larger viewport side · 1vmax = max(viewport width, height) ÷ 100.ビューポートのサイズ
ch長さ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.フォントメトリクス(文字幅 / x ハイト)
ex長さx-height · 1ex is the font’s x-height, usually about half the font size and very font-dependent.フォントメトリクス(文字幅 / x ハイト)
lh長さCurrent line height · 1lh equals the element’s computed line-height, which makes line-aligned spacing trivial.行の高さ
rlh長さRoot line height · 1rlh equals the root element’s line-height and ignores the current element.ルートのフォントサイズ, 行の高さ
deg角度Degree · A full circle is 360deg; the most common angle in transforms and gradients.なし(絶対単位)
rad角度Radian · A full circle is 2π rad ≈ 6.2832rad, so 1rad = 180/π deg ≈ 57.2958deg.なし(絶対単位)
turn角度Turn · 1turn = 360deg, the clearest way to write a full rotation.なし(絶対単位)
s時間Second · 1s = 1000ms, the default unit for transitions and animations.なし(絶対単位)
ms時間Millisecond · 1ms = 0.001s.なし(絶対単位)
dpi解像度Dots per inch · 1dpi = 1/2.54 dpcm and 1dppx = 96dpi; prefer dppx in media queries.なし(絶対単位)
dpcm解像度Dots per centimetre · 1dpcm = 2.54/96 dppx ≈ 0.0265dppx.なし(絶対単位)
dppx解像度Dots per pixel · The device pixel ratio: 1dppx = 96dpi, and Retina displays are usually 2dppx.なし(絶対単位)
fr可変の割合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.なし(絶対単位)

このツールでできること

  • デザインカンプの px を rem / em に変換:ルートのフォントサイズと親のフォントサイズを入力すれば、16px = 1rem、16px = 0.8em(親が 20px)といった結果がすぐに得られます。
  • レスポンシブな文字サイズを書く前に vw 値を計算:ビューポートが 1280px なら 16px は 1.25vw で、百分率の手計算ミスを避けられます。
  • 単位の意味を確認:ch はどれくらいの幅か、ex や lh はいつ使うのか、1Q は何 px か、dpcm と dppx はどう換算するのか。リファレンス表に依存関係の説明があります。
  • 「ネストするほど文字が大きくなる」といった問題の調査:em と % は親要素に対して積み重なるため、どの結果が親のフォントサイズに依存するかをツールが明示します。

例

入力

数値 16、元の単位 px、変換先の単位 rem、ルートのフォントサイズ 16px、親のフォントサイズ 20px、ビューポート 1280 × 720

出力

16px = 1rem(依存先:ルートのフォントサイズ);同じ数値は em で 0.8em(依存先:親のフォントサイズ)、% で 80%、vw で 1.25vw、cm で 0.423333cm(前提に依存しない)

px と cm の間は絶対長の換算で、どのような前提にも依存しないため「前提に依存しない」と表示されます。

よくある質問

換算結果に「前提に依存する」と付くのはなぜですか?

CSS で固定値を持つのは絶対長(px、in、cm、mm、q、pt、pc)だけです。em は親要素のフォントサイズ、rem はルートのフォントサイズ、% は親要素の同名プロパティ、vw / vh はビューポート、ch / ex はフォントメトリクス、lh / rlh は行の高さに依存します。同じ 2em でも前提が違えば px 値は変わるため、依存先を併記しています。

em と rem は結局どこが違うのですか?

rem はルート要素(html)のフォントサイズだけを見るので、ネストの深さに影響されません。em は現在の要素のフォントサイズを見ますが、そのフォントサイズ自体が親に対して宣言されることが多く、階層ごとに掛け算になります。余白や角丸のように安定した値が必要な場所は rem、「文字サイズに比例させたい」場所(アイコンと文字の整列など)は em を使います。

画面上の pt、cm、in は実際の物理サイズですか?

いいえ。CSS は 1in = 96px と定めているため、pt、cm、mm はその比率で換算した CSS ピクセルにすぎず、印刷した物理長とは関係ありません。実際の印刷時にはブラウザがデバイスの解像度に合わせて再マッピングします。印刷サイズを正確に制御するには @page と mm を使ってください。

fr が換算できないのはなぜですか?

fr は「余った空間の 1 份」を表し、grid のトラックサイズの中でのみ有効です。そのピクセル値は同じ grid-template 内の他のトラックがどれだけ空間を使うかに依存するため、レイアウトの前提から離れると確定値を持ちません。そのためツールは換算を拒否します。

ビューポートの幅と高さはどの値を入れますか?

デバッグ中に実際に見えているレイアウトビューポートのサイズ(スクロールバーの影響を含む幅)を入れてください。vw はその 1% です。モバイルではアドレスバーの表示・非表示でビューポートの高さが変わり vh の px 値も変わる点に注意が必要で、これは svh / lvh / dvh で解決できます。

キーワード:css unitspx to rempx to emvw vhunit converter

関連ツール