max-width

  • Revision slug: CSS/max-width
  • Revision title: max-width
  • Revision id: 25731
  • Created:
  • Creator: Potappo
  • Is current revision? No
  • Comment /* Syntax */ new names, per bug 402706

Revision Content

{{template.CSSRef()}}

Summary

The max-width property is used to set the maximum width of a given element. It prevents the used value of the {{template.Cssxref("width")}} property from becoming larger than the value specified for max-width.

  • {{template.Xref_cssinitial()}}: {{template.Cssxref("none")}}
  • Applies to: block level and replaced elements
  • {{template.Xref_cssinherited()}}: no
  • Percentages: refer to the width of the containing block
  • Media: {{template.Xref_cssvisual()}}
  • {{template.Xref_csscomputed()}}:

Syntax

max-width: <length> | <percentage> | none | -moz-max-content | -moz-min-content | -moz-fit-content | -moz-available

Values

  • none : the {{template.Cssxref("width")}} has no maximum value
  • length : can be in px, cm, in
  • percentage : % specified as a percentage of containing block's width
  • -moz-max-content : the intrinsic preferred width {{template.Fx_minversion_inline(3)}}
  • -moz-min-content : the intrinsic minimum width {{template.Fx_minversion_inline(3)}}
  • -moz-available : the containing block width minus horizontal margin, border, and padding {{template.Fx_minversion_inline(3)}}
  • -moz-fit-content : the same as -moz-max-content {{template.Fx_minversion_inline(3)}}

Examples

{{template.CSSRefExampleLink("max-width")}}

table{max-width: 75%;}

form{max-width: none;}

Notes

{{template.Cssxref("max-width")}} overrides width, but {{template.Cssxref("min-width")}} overrides {{template.Cssxref("max-width")}}.

Specifications

Browser compatibility

Browser Lowest Version
Internet Explorer 6
Netscape 6
Opera 3.5

See also

box model, {{template.Cssxref("max-height")}}, {{template.Cssxref("-moz-box-sizing")}}, {{template.Cssxref("width")}}, {{template.Cssxref("min-width")}}

{{ wiki.languages( { "fr": "fr/CSS/max-width" } ) }}

Revision Source

<p> 
{{template.CSSRef()}}
</p>
<h3 name="Summary"> Summary </h3>
<p>The <code>max-width</code> property is used to set the maximum width of a given element.  It prevents the used value of the {{template.Cssxref("width")}} property from becoming larger than the value specified for <code>max-width</code>.
</p>
<ul><li> {{template.Xref_cssinitial()}}: {{template.Cssxref("none")}}
</li><li> Applies to: block level and replaced elements
</li><li> {{template.Xref_cssinherited()}}: no
</li><li> Percentages: refer to the width of the containing block
</li><li> Media: {{template.Xref_cssvisual()}}
</li><li> {{template.Xref_csscomputed()}}:
</li></ul>
<h3 name="Syntax"> Syntax </h3>
<p>max-width: &lt;length&gt; | &lt;percentage&gt; | none | -moz-max-content | -moz-min-content | -moz-fit-content | -moz-available
</p>
<h3 name="Values"> Values </h3>
<ul><li> <b>none</b> : the {{template.Cssxref("width")}} has no maximum value
</li><li> <b>length</b> : can be in px, cm, in 
</li><li> <b>percentage</b> : % specified as a percentage of containing block's width 
</li><li> <b>-moz-max-content</b> : the intrinsic preferred width {{template.Fx_minversion_inline(3)}}
</li><li> <b>-moz-min-content</b> : the intrinsic minimum width {{template.Fx_minversion_inline(3)}}
</li><li> <b>-moz-available</b> : the containing block width minus horizontal margin, border, and padding {{template.Fx_minversion_inline(3)}}
</li><li> <b>-moz-fit-content</b> : the same as <code>-moz-max-content</code> {{template.Fx_minversion_inline(3)}}
</li></ul>
<h3 name="Examples"> Examples </h3>
<p>{{template.CSSRefExampleLink("max-width")}}
</p>
<pre>table{max-width: 75%;}

form{max-width: none;}
</pre>
<h3 name="Notes"> Notes </h3>
<p>{{template.Cssxref("max-width")}} overrides width, but {{template.Cssxref("min-width")}} overrides {{template.Cssxref("max-width")}}.
</p>
<h3 name="Specifications"> Specifications </h3>
<ul><li> <a class="external" href="http://www.w3.org/TR/CSS2/visudet.html#min-max-widths">CSS 2.1</a>
</li></ul>
<h3 name="Browser_compatibility"> Browser compatibility </h3>
<table class="standard-table">
  <tbody><tr>
    <th>Browser</th>
    <th>Lowest Version</th>
  </tr>
  <tr>
    <td>Internet Explorer</td>
    <td>6</td>
  </tr>
  <tr>
    <td>Netscape</td>
    <td>6</td>
  </tr>
  <tr>
    <td>Opera</td>
    <td>3.5</td>
  </tr>
</tbody></table>
<h3 name="See_also"> See also </h3>
<p><a href="en/CSS/box_model">box model</a>, {{template.Cssxref("max-height")}}, {{template.Cssxref("-moz-box-sizing")}}, {{template.Cssxref("width")}}, {{template.Cssxref("min-width")}}
</p>
<div class="noinclude">
</div>
{{ wiki.languages( { "fr": "fr/CSS/max-width" } ) }}
Revert to this revision