CSS widthProperty
Example
Set the height and width of a paragraph:
p.ex
{
height:100px;
width:100px;
}
{
height:100px;
width:100px;
}
Try it Yourself »
More examples at the bottom of this page.
Property definition and usage instructions
The width property sets the width of an element.
Note:The width property does not include padding, borders, or margins!
| Default value: | auto |
|---|---|
| Inherited: | no |
| version: | CSS1 |
| JavaScript Syntax: | object.style.width="50px" |
Browser Support
The numbers in the table specify the first browser version that fully supports the property.
| Property | |||||
|---|---|---|---|---|---|
| width | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Property value
| Value | Description |
|---|---|
| auto | Default value. The browser calculates the actual width. |
| length | Defines the width in units such as px, cm, etc. |
| % | Defines the width as a percentage of the containing block's (parent element's) width. |
| inherit | Specifies that the value of the width property should be inherited from the parent element. |
More Examples
Set the width of an element using a percentage
This example demonstrates how to set the width of an element using a percentage value.
Related Articles
CSS Tutorial:CSS Dimension
CSS Tutorial:CSS Box model
CSS Reference Manual:height Attribute
other extensions