English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS Reference Manual

CSS @rules (RULES)

Comprehensive CSS Properties

CSS max-Usage and examples of width attribute

max-The maximum width of the content area of the element specified by the width CSS property. This maximum width does not include padding, border, or margin.-Please refer toCSS box model.

The following table provides usage instructions and version history of this attribute, as well as the syntax of using this attribute in JavaScript scripts.

Default value:none
Applies to:All elements except for unreplaced embedded elements, table rows, and row groups
Inheritance:No
Animatable:Yes.Please refer to Animation properties.
Version:CSS 2,3
JavaScript syntax:object.style.maxWidth="200px"

max-Syntax of width usage

The syntax of this attribute is as follows:

max-width: length | percentage | none | initial | inherit

The following examples demonstrate how to use max-width attribute.

  p {
   max-width: 400px;
  }
  div {
   width: 300px;
   max-width: 200px;
  }
Test and see‹/›

Attribute value

The following table describes the value of this property.

ValueDescription
lengthThe specified maximum width, in px, pt, cm, em, etc. Negative values are not allowed.
percentageMaximum width, in percentage. The percentage is calculated relative to the width of the element's containing block. Negative percentage values are not allowed.
noneNo maximum width. This is the default value.
initialSet this property to its default value.
inheritIf specified, the associated element adopts the max of its parent element.-The value of the width property.

Browser compatibility

max-Browser compatibility of the width attribute; the numbers in the table below represent the minimum version number of browsers that support this attribute; all mainstream browsers support this attribute.

  • Firefox 1+

  • Google Chrome1+

  • Internet Explorer 7+

  • Apple Safari 1+

  • Opera 7+

For further reading

Please refer to the tutorials related to the following content:CSS Box Model,CSS dimensions.

Related properties:width,min-width.