Style maxWidth Property

Example

Set the maximum width of a <div> element:

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

Description

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

Property
maxWidth Yes Yes Yes Yes Yes

Syntax

Return the maxWidth property:

object.style.maxWidth

Set the maxWidth property:

object.style.maxWidth = "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

Example

Return the maximum width of a <div> element:

alert(document.getElementById("myDiv").style.maxWidth);
Try it Yourself »

Related Pages

CSS tutorial: CSS Dimension

CSS reference: max-width property


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.