Style maxWidth property
- Previous Page maxHeight
- Next Page minHeight
- Go to the Previous Level HTML DOM Style Object
Definition and Usage
maxWidth
Sets or returns the maximum width of an element.
maxWidth
The property is only effective for block-level elements or elements with absolute or fixed positioning.
Note:The width of the element can never be greater than maxWidth
The value specified by the property.
Tip:To set or return the minimum width of an element, use minWidth property.
See also:
CSS Tutorial:CSS Dimension
CSS Reference Manual:max-width property
Example
Example 1
Set the maximum width of the <div> element:
document.getElementById("myDiv").style.maxWidth = "100px";
Example 2
Return the maximum width of the <div> element:
alert(document.getElementById("myDiv").style.maxWidth);
Syntax
Return maxWidth property:
object.style.maxWidth
Set maxWidth property:
object.style.maxWidth = "none|length|%|initial|inherit"
Property value
Value | Description |
---|---|
none | The width of the element is not restricted. Default. |
length | Define the maximum width with a length unit. |
% | Define the maximum width as a percentage of the parent element. |
initial | Set this property to its default value. See also initial. |
inherit | Inherit this property from its parent element. See also inherit. |
Technical Details
Default value: | None |
---|---|
Return value: | A string that represents the maximum width of an element. |
CSS Version: | CSS2 |
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |
- Previous Page maxHeight
- Next Page minHeight
- Go to the Previous Level HTML DOM Style Object