May 06, 2021 CSS Reference Manual
The width property sets the width of the element.
Note: width properties do not include padding, borders, and margins!
Default: | auto |
---|---|
Inherited: | no |
Version: | CSS1 |
JavaScript syntax: | object .style.width="50px" |
Value | Describe |
---|---|
auto | The default. The browser calculates the actual width. |
length | Define the width in px, cm, and other units. |
% | Defines the percentage width based on the width of the containing block (parent element). |
inherit | Specifies that the value of the width property should be inherited from the parent element. |
The numbers in the table support the first browser version number of the property.
Attributes | |||||
---|---|---|---|---|---|
width | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Use percentages to set the width of an element
This example shows how to use a percentage value to set the width of an element.
CSS tutorial: CSS Dimension
CSS tutorial: CSS Box model
CSS Reference Manual: Height Properties