CSS Property max-width

max-width sets a maximum constraint on the width of the element.


Initial value none
Inherited No.
Version CSS2
JavaScript syntax object.style.maxWidth="10px"
Applies to All elements except inline nonreplaced elements and table elements.

CSS Syntax

max-width: length | percentage | inherit 

Property Values

The property values are listed in the following table.

auto Default value. The browser does the calculation.
length Set width in px, cm, etc.
% Set width in percent of the containing element
inherit Inherit the width property from the parent element

Browser compatibility

max-width Yes Yes Yes Yes Yes


An example showing how to use max-width CSS property.

        <style type='text/css'>
      p {<!-- w ww. j a  va  2s .c  om-->
          padding: 10px;
          margin: 10px;
          border: thin solid black;
          width: auto;
          max-width: 500px;
        This is a test. This is a test. 

Click to view the demo