Style width property
The Style object
Definition and Usage
The width property sets or returns the width of an element.
The width property only works on block-level elements or absolutely/fixed positioned elements. Overflowing content can be restricted by the overflow property.
Syntax
Set the width property:
Object.style.width="auto|
length|%
|inherit"
Return the width property:
Object.style.width
| Value | Description |
|---|---|
| auto | Default. The width set by the browser. |
| length | Defines the width using units such as px and cm. |
| % | Defines the width as a percentage of the parent element. |
| inherit | The value of the width property is inherited from the parent element. |
Browser support





All major browsers support the width 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
Set the width of a button:
Try it »
The Style object