CSS width attribute
- previous page widows
- next page word-break
Definition and Usage
Sets the width of the element.
Description
This property defines the width of the element's content area, where padding, borders, and margins can be added outside the content area.
Inline non-replaced elements will ignore this property.
See Also:
CSS Tutorial:CSS Dimensions
CSS Tutorial:Overview of CSS Box Model
CSS Reference Manual:height property
HTML DOM Reference Manual:width property
CSS Syntax
width: auto|value|initial|inherit;
Property Value
Value | Description |
---|---|
auto | Default Value. The browser can calculate the actual width. |
length | Define the width using units such as px, cm, etc. |
% | Defines a percentage width based on the width of the containing block (parent element). |
inherit | Specifies that the width property should be inherited from the parent element. |
Technical Details
Default Value: | auto |
---|---|
Inheritance: | no |
Version: | CSS1 |
JavaScript Syntax: | object.style.width="50px" |
Try It Yourself Example
- Set the width of an element using pixel values
- This example demonstrates how to set the width of an element using pixel values.
- Set the width of an element using percentages
- This example demonstrates how to set the width of an element using percentage values.
Browser support
The numbers in the table indicate the first browser version that fully supports this attribute.
Chrome | IE / Edge | Firefox | Safari | Opera |
---|---|---|---|---|
1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
- previous page widows
- next page word-break