max-height

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

* Some parts of this feature may have varying levels of support.

max-heightCSS のプロパティで、要素の最大高を設定します。これは height プロパティの使用値が、 max-height に指定した値を上回ることを防ぎます。

試してみましょう

max-heightheight を上書きしますが、 min-heightmax-height を上書きします。

構文

css
/* <length> 値 */
max-height: 3.5em;
max-height: anchor-size(height);
max-height: calc(anchor-size(--myAnchor self-block, 250px) + 2em);

/* <percentage> 値 */
max-height: 75%;

/* キーワード値 */
max-height: none;
max-height: max-content;
max-height: min-content;
max-height: fit-content;
max-height: fit-content(20em);
max-height: stretch;

/* グローバル値 */
max-height: inherit;
max-height: initial;
max-height: revert;
max-height: revert-layer;
max-height: unset;

<length>

max-height を絶対的な値で定義します。

<percentage>

max-height を包含ブロックの高さに対するパーセント値で定義します。

none

ボックスの寸法を制限しません。

max-content

内容物が推奨する max-height です。

min-content

内容物の最小の max-height です。

fit-content

利用できる空間を使用しますが、 max-content を超えないようにします。すなわち、 min(max-content, max(min-content, stretch)) です。

fit-content(<length-percentage>)

利用可能な空白を指定された引数で置き換えた fit-content 式を使用します。すなわち、 min(max-content, max(min-content, 引数)) です。

stretch

要素のマージンボックスの最大の高さを、包含ブロックの高さに制限します。マージンボックスが包含ブロック内で利用できる空間をすべて満たそうとするため、 100% と似たような動作をしますが、結果として得られるサイズは box-sizing で決定されるボックスではなく、マージンボックスに適用されます。

メモ: ブラウザーが stretch 値のために使用する別名と実装状況については、ブラウザーの互換性の節を参照してください。

アクセシビリティ

テキストを大きくするためにページを拡大したときに、 max-height を設定した要素が切り取られたり、他のコンテンツを覆い隠したりしないことを確認してください。

公式定義

初期値none
適用対象非置換インライン要素、テーブルの列、列グループを除くすべての要素
継承なし
パーセント値パーセント値は、生成ボックスの包含ブロックの高さを基準に計算されます。 包含ブロックの高さが明示的に定義されず (すなわち、コンテンツの高さに依存します)、この要素が絶対位置指定されていない場合は、パーセント値は none として扱われます。
計算値指定されたパーセント値または絶対的な長さ、または none
アニメーションの種類length または パーセント値, calc();

形式文法

max-height = 
none |
<length-percentage [0,∞]> |
min-content |
max-content |
fit-content( <length-percentage [0,∞]> ) |
<calc-size()> |
<anchor-size()>

<length-percentage> =
<length> |
<percentage>

<calc-size()> =
calc-size( <calc-size-basis> , <calc-sum> )

<anchor-size()> =
anchor-size( [ <anchor-name> || <anchor-size> ]? , <length-percentage>? )

<calc-size-basis> =
<intrinsic-size-keyword> |
<calc-size()> |
any |
<calc-sum>

<calc-sum> =
<calc-product> [ [ '+' | '-' ] <calc-product> ]*

<anchor-name> =
<dashed-ident>

<anchor-size> =
width |
height |
block |
inline |
self-block |
self-inline

<calc-product> =
<calc-value> [ [ '*' | '/' ] <calc-value> ]*

<calc-value> =
<number> |
<dimension> |
<percentage> |
<calc-keyword> |
( <calc-sum> )

<calc-keyword> =
e |
pi |
infinity |
-infinity |
NaN

パーセント値とキーワード値を用いた max-height の設定

css
table {
  max-height: 75%;
}

form {
  max-height: none;
}

仕様書

Specification
CSS Box Sizing Module Level 4
# width-height-keywords
CSS Box Sizing Module Level 4
# sizing-values

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
max-height
anchor-size()
Experimental
fit-content
fit-content()
Experimental
max-content
min-content
none
stretch
Experimental

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.
User must explicitly enable this feature.
Uses a non-standard name.
Requires a vendor prefix or different name for use.
Has more compatibility info.

関連情報