Style maxWidth Property

Style Object Reference Style Object


Set the maximum width of a <div> element:

document.getElementById("myDiv").style.maxWidth = "100px";
Try it Yourself »

Definition and Usage

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

The maxWidth property has effect only on block-level elements or on elements with absolute or fixed position.

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

Tip: To set or return the minimum width of an element, use the minWidth property.

Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The maxWidth property is supported in all major browsers.


Return the maxWidth property:

Set the maxWidth property:"none|length|%|initial|inherit"

Property Values

Value Description
none No limit on the width of the element. This is default
length Defines the maximum width in length units
% Defines the maximum width in % of the parent element
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit

Technical Details

Default Value: none 
Return Value: A String, representing the maximum width of an element
CSS Version CSS2

More Examples


Return the maximum width of a <div> element:

Try it Yourself »

Related Pages

CSS tutorial: CSS Dimension

CSS reference: max-width property

Style Object Reference Style Object