Easy Tutorial
❮ Dom Obj Map Prop Nav Appversion ❯

Style width Property


Definition and Usage

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

The width property only works on block-level elements or elements with absolute/fixed positioning. Overflowing content can be constrained by the overflow property.

Syntax

Setting the width property:

Returning the width property:

Value Description
auto Default. The width set by the browser.
length Defines the width using units like px, cm, etc.
% 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 requires a !DOCTYPE to support "inherit". IE9 supports "inherit".


Example

Setting the width of a button:

❮ Dom Obj Map Prop Nav Appversion ❯