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)同士の換算は前提に依存しません。
結果
| 単位 | 値 | 説明 |
|---|---|---|
| px | 16 | 前提に依存しない |
| in | 0.166667 | 前提に依存しない |
| cm | 0.423333 | 前提に依存しない |
| mm | 4.233333 | 前提に依存しない |
| q | 16.933333 | 前提に依存しない |
| pt | 12 | 前提に依存しない |
| pc | 1 | 前提に依存しない |
| em | 0.8 | 前提に依存 |
| rem | 1 | 前提に依存 |
| % | 80 | 前提に依存 |
| vw | 1.25 | 前提に依存 |
| vh | 2.222222 | 前提に依存 |
| vmin | 2.222222 | 前提に依存 |
| vmax | 1.25 | 前提に依存 |
| ch | 1.6 | 前提に依存 |
| ex | 1.6 | 前提に依存 |
| lh | 0.533333 | 前提に依存 |
| rlh | 0.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