Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM Style maxWidth Property

Style maxWidth Property

Style Object Reference The Style object


Definition and Usage

The maxWidth property sets or returns the maximum width of an element.

The maxWidth property only takes effect on block-level elements or absolutely/fixed-positioned elements.

**Note:** The width of an element can never be greater than the value specified by the maxWidth property.

Syntax

Sets the maxWidth property:

Object.style.maxWidth="none|

length|%

|inherit"

Returns the maxWidth property:

Object.style.maxWidth

Value Description
none Default. The width of the element is not limited.
length Defines the maximum width using units such as px, cm, etc.
% Defines the maximum width as a percentage of the parent element.
inherit The maxWidth property value is inherited from the parent element.

Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the maxWidth property.

**Note:** IE7 and earlier versions do not support the "inherit" value. IE8 supports "inherit" only if a !DOCTYPE is specified. IE9 supports "inherit".


Example

Example

Sets the maximum width of an element:

Runoob Tutorial(runoob.com)

This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.

Try it »


Style Object Reference The Style object