この記事はまだボランティアによって 日本語 に翻訳されていません。ぜひ MDN に参加して翻訳を手伝ってください!
この記事を English (US) で読むこともできます。

The min() CSS function lets you set the smallest (most negative) value from a list of comma-separated expressions as the value of a CSS property value. The min() function can be used anywhere a <length>, <frequency>, <angle>, <time>, <percentage>,<number>, or <integer> is allowed.

/* property: min(expression [, expression]) */
width: min(10vw, 4em, 80px);

In the above example, the width will be at most 80px, but will be narrower if the the viewport is less than 800px wide, or an em is less than 20px wide. In other words, the max-width is 80px. Think of the min() value as providing the maximum value a property can have.

Syntax

The min() function takes one or more comma separated expressions as its parameter, with the smallest (most negative) expression value result used as the value. The expresstions can be math functions (see calc() for more information), literal values, or other expressions, such as attr(), that evaluate to a valid argument type (like <length>). You can use different units for each value in your expression, if you wish. You may also use parentheses to establish computation order when needed.

Notes

  • Math expressions involving percentages for widths and heights on table columns, table column groups, table rows, table row groups, and table cells in both auto and fixed layout tables may be treated as if auto had been specified.
  • It is permitted to nest max() and other min() functions as expression values. The expressions are full math expressions, so you can use direct addition, subtraction, multiplication and division without using the calc() function itself.
  • The expression can be values combining the addition ( + ), subtraction ( - ), multiplication ( * ) and division ( / ) operators, using standard operator precedence rules. Make sure to put a space on each side of the + and - operands. The operands in the expression may be any <length> syntax value. You can use different units for each value in your expression. You may also use parentheses to establish computation order when needed.
  • Oftentimes you will want to comine min() and max() values, or use min() within a clamp() or calc() function.
  • You can provide more than two arguments, if you have multiple constraints to apply.

Formal syntax

min( <calc-sum># )

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

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

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

Examples

Growing images to a maximum size

min() makes it easy to set a maximum width for an image. In this example, the CSS creates a logo that stretches half way across the window on smaller devices, but does not not exceed 300px on wider devices, without the use of media queries:

.logo {
  width: min(50vw, 300px);
}
<img src="https://developer.mozilla.org/static/img/web-docs-sprite.svg" alt="MDN Web Docs" class="logo">

In this example, the logo will be 300px wide unless the viewport narrows below 600px, at which point it will shrink as the viewport shrinks, always being 50% of the width of the viewport.

Setting a maximum size for an label and input

Another use case for CSS functions is to set a maximum size on responsive form controls: enabling the width of labels and inputs to shrink as the width of the form shrinks

Let's look at some CSS:

input, label {
  padding: 2px;
  box-sizing: border-box;
  display: inline-block;
  width: min(40%, 400px);
  background-color: pink;
}

form {
  margin: 4px;
  border: 1px solid black;
  padding: 4px;
}

Here, the form itself, along with the margin, border, and padding, will be 100% of it's parent's width. We declare the input and label to be the lesser of 40% of the form width up to the padding or 400px wide, whichever is smaller. In other words, the widest, or max-width, the label and input will be is 400px. The narrowest they will be is 40% of the form's width, which on a watch is going to be very small.

<form>
  <label>Type something:</label>
  <input type="text">
</form>

Think of the min() function as finding the maximum value allowed for a property.

Accessibility concerns

When min() is used for controlling text size, make sure the text is always large enough to read. A suggestion is to use the min() function nested within a max() that has as its second value a relative length unit that is always large enough to read. For example:

small {
  font-size: max(min(0.5vw, 0.5em), 1rem);
}

This ensures a minimum size of 1rem, with a text size that will scale if the page is zoomed.

Specifications

Specification Status Comment
CSS Values and Units Module Level 4
The definition of 'min()' in that specification.
Editor's Draft Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
<min()>
Experimental
Chrome No support NoEdge No support NoFirefox No support NoIE No support NoOpera No support NoSafari Full support 11.1WebView Android No support NoChrome Android No support NoFirefox Android No support NoOpera Android No support NoSafari iOS Full support 11.1Samsung Internet Android No support No

Legend

Full support  
Full support
No support  
No support
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.

See also

ドキュメントのタグと貢献者

このページの貢献者: QuentinA, mdnwebdocs-bot, ExE-Boss, estelle
最終更新者: QuentinA,