Aspect Ratio Calculator
幅×高さから既約アスペクト比を計算。比率ロックで寸法を逆算し、CSSスニペットをコピーできます。
寸法 → 比率 / Dimensions to Ratio
比率ロック計算 / Ratio-Locked Dimensions
CSS スニペット / CSS Snippets現在の比率: 16:9
.box {
aspect-ratio: 16 / 9;
}aspect-ratio (Chrome 88+ / Safari 15+)
.box {
position: relative;
width: 100%;
}
.box::before {
content: "";
display: block;
padding-top: 56.25%; /* 9 / 16 * 100 */
}padding-top ハック (旧ブラウザ互換)
How to Use the Aspect Ratio Calculator
This free online aspect ratio calculator reduces any width and height to its simplest ratio using the greatest common divisor (GCD). Enter 1920 and 1080 and you instantly get 16:9 along with the decimal value 1.7778. You can then lock that ratio and compute a missing dimension — type a width of 1280 at 16:9 and the height 720 appears automatically.
Features
- GCD-based ratio reduction, including decimal ratios such as 1.91:1 and 1:1.414 (A4)
- Ratio-locked dimension calculation: enter either width or height, get the other
- Presets for 16:9, 4:3, 1:1, 9:16 (vertical video), 21:9, 1.91:1 (OGP), 3:2, and A4
- Copyable CSS snippets: the modern
aspect-ratioproperty and the legacy padding-top hack - Recommended size charts for YouTube, Instagram, OGP, and TikTok/Shorts
- Runs entirely in your browser — no data is ever sent to a server
What is an aspect ratio?
An aspect ratio describes the proportional relationship between the width and height of an image, video, or screen. It is written as two numbers separated by a colon, such as 16:9. Two different resolutions can share the same aspect ratio: 1280x720, 1920x1080, and 3840x2160 are all 16:9 because each pair reduces to the same fraction. Keeping the aspect ratio constant while resizing prevents stretching and distortion, which is why responsive image and video containers in CSS are built around a fixed ratio rather than fixed pixels.
Aspect Ratio Calculatorの使い方
幅と高さ(例: 1920×1080)を入力すると、最大公約数(GCD)で割った既約比率(16:9)と小数値(1.7778)が即座に表示されます。 「この比率をロック計算で使う」で比率を固定すれば、幅か高さの一方を入力するだけでもう一方が自動計算されます。 プリセットには動画・SNS・印刷で頻出する8種類の比率を用意しました。計算結果はCSSのaspect-ratioプロパティとpadding-topハックの2形式でコピーできます。
実務での活用例
1. SNS・動画プラットフォームの推奨サイズ確認
サムネイルやOGP画像を作るとき、プラットフォームごとの推奨比率を毎回調べるのは手間です。主要な推奨サイズを以下にまとめました。
| 用途 / Use | 推奨サイズ / Size | 比率 / Ratio |
|---|---|---|
| YouTube サムネイル | 1280×720 | 16:9 |
| YouTube 動画 (フルHD) | 1920×1080 | 16:9 |
| Instagram フィード (正方形) | 1080×1080 | 1:1 |
| Instagram フィード (縦長) | 1080×1350 | 4:5 |
| OGP (X / Facebook リンクカード) | 1200×630 | 約1.91:1 (正確には40:21) |
| TikTok / YouTube Shorts / リール | 1080×1920 | 9:16 |
2. レスポンシブな動画埋め込みのCSS作成
YouTube埋め込みのiframeは幅に追従して高さが決まらないため、コンテナ側で比率を固定する必要があります。 16:9をプリセットで選び、aspect-ratio: 16 / 9をコピーして適用すれば、どの画面幅でも黒帯やはみ出しが発生しません。 Safari 14以前をサポートする案件では、もう一方のpadding-topハック(56.25%)を使います。
3. 画像リサイズ時の縦横計算
元画像3000×2000(3:2)をバナー幅1200pxに縮小する場合、比率ロックに3:2を設定して幅1200を入力すると高さ800が即座に得られます。 実際の縮小処理はImage Resizer、切り抜きで比率を変える場合はImage Cropperと組み合わせると効率的です。
よくあるエラーと対処 / Common Errors and Fixes
アスペクト比計算とCSS適用でつまずきやすいポイントをまとめました。
Common pitfalls when calculating aspect ratios and applying them in CSS.
| エラー / Error | 原因 / Cause | 対処 / Fix |
|---|---|---|
| 比率が「-」のまま表示されない | 幅・高さが未入力、または0以下 Width or height is empty or not positive | 両方に0より大きい数値を入力 Enter positive numbers in both fields |
| 1920×1200 が 16:9 にならない | 1920×1200 は 16:10(既約で8:5)。16:9 は 1920×1080 1920x1200 is 16:10 (8:5 reduced), not 16:9 | 入力値を確認。WUXGA(16:10)とフルHD(16:9)は別物 Check the input; WUXGA (16:10) differs from Full HD (16:9) |
aspect-ratio が効かない | Safari 14以前・Chrome 87以前は未対応 Unsupported in Safari ≤14 / Chrome ≤87 | padding-top ハックのスニペットを使用 Use the padding-top hack snippet instead |
padding-top: 56.25% で高さが0になる | 親要素の幅が0。padding の % は親の「幅」基準 Parent width is 0; percentage padding resolves against the parent's width | 親要素に width を指定するGive the parent element an explicit width |
| 逆算した寸法が小数になる | 比率で割り切れない値(例: 16:9 で幅1000 → 高さ562.5) The dimension is not divisible by the ratio (e.g. width 1000 at 16:9 gives 562.5) | 本ツールは小数第2位で丸め。ピクセルでは整数に四捨五入して1px以内の誤差を許容 Rounded to 2 decimals here; round to integer pixels and accept ≤1px error |
| 1.91:1 と入力すると 191:100 と表示される | 小数比率は10000倍して整数化後にGCDで既約化する仕様 Decimal ratios are scaled to integers before GCD reduction | 正常動作。CSSの aspect-ratio: 191 / 100 は 1.91 と等価Expected behavior; aspect-ratio: 191 / 100 equals 1.91 |
| 縦動画なのに横長の比率が出る | 幅と高さを逆に入力(1920×1080 と 1080×1920 は別) Width and height swapped (1920x1080 vs 1080x1920) | 縦動画は「幅1080 × 高さ1920」= 9:16 で入力 For vertical video enter width 1080 x height 1920 = 9:16 |
言語別コード例 / Code Examples by Language
GCDによる既約化と比率ロック計算をコードで再現する最小サンプルです。
Minimal snippets to reduce ratios with GCD and compute ratio-locked dimensions.
JavaScript / TypeScript
// 最大公約数 / Greatest common divisor
const gcd = (a, b) => (b === 0 ? a : gcd(b, a % b));
// 1920x1080 -> "16:9"
function aspectRatio(w, h) {
const g = gcd(w, h);
return `${w / g}:${h / g}`;
}
// 比率ロック / Height from width at 16:9
const height = Math.round((1280 * 9) / 16); // 720Python
from math import gcd
from fractions import Fraction
def aspect_ratio(w: int, h: int) -> str:
g = gcd(w, h)
return f"{w // g}:{h // g}"
print(aspect_ratio(1920, 1080)) # 16:9
print(Fraction(1200, 630)) # 40/21 (OGPの実比率 約1.905)Go
func gcd(a, b int) int {
for b != 0 {
a, b = b, a%b
}
return a
}
func aspectRatio(w, h int) string {
g := gcd(w, h)
return fmt.Sprintf("%d:%d", w/g, h/g) // 1920, 1080 -> "16:9"
}CSS
/* モダン / Modern (Chrome 88+, Safari 15+, Firefox 89+) */
.video { aspect-ratio: 16 / 9; }
/* 旧ブラウザ向け / Legacy padding-top hack */
.video-wrap { position: relative; width: 100%; }
.video-wrap::before {
content: "";
display: block;
padding-top: 56.25%; /* 9 / 16 * 100 */
}Before / After 実例 / Before & After
例1: 解像度から既約比率を求める / Reduce a resolution to its ratio
幅 1920 × 高さ 1080↓ GCD = 120 で既約化
16:9 (1.7778 : 1)例2: OGP画像の実際の比率 / The real ratio of an OGP image
幅 1200 × 高さ 630↓ GCD = 30 で既約化
40:21 (1.9048 : 1) ※ 通称 "1.91:1"例3: 比率ロックで高さを逆算してCSS化 / Lock 16:9 and generate CSS
比率 16:9、幅 1280 を入力↓
高さ 720
.box {
aspect-ratio: 16 / 9;
}
/* または padding-top: 56.25%; */padding-top の % は「高さ ÷ 幅 × 100」。16:9 なら 9 ÷ 16 × 100 = 56.25% です。
The padding-top percentage is height / width x 100; for 16:9 that is 9 / 16 x 100 = 56.25%.
Why browser-only? / なぜブラウザ完結か
An aspect ratio calculator may look harmless, but the numbers you type often describe unreleased work: banner dimensions for an unannounced campaign, screen sizes of an unshipped device, or layout specs from a client's private design system. A server-side calculator receives every keystroke as a request, and those requests can be logged, aggregated, or leaked. DevToolBox performs the GCD reduction, the ratio-locked dimension math, and the CSS snippet generation entirely in your browser with plain JavaScript. No network request is made after the page loads, nothing is stored, and you can verify this yourself: open DevTools, switch to the Network tab, use the calculator, and watch the tab stay empty. The tool also works offline once loaded, which makes it safe to use on restricted corporate networks.
入力する数値は「未公開キャンペーンのバナーサイズ」「未発表デバイスの画面解像度」など、公開前の情報であることが少なくありません。 本ツールはGCD計算・寸法逆算・CSS生成をすべてブラウザ内のJavaScriptで実行し、ページ読み込み後は一切の通信を行いません。 DevTools の Network タブが空のままであることで、外部送信がないことを自身で確認できます。
関連ツール / Related Tools
開発をもっと効率的に
PR