Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSS width property

CSS width property

Example

Set the height and width of a paragraph:

p.ex

{

height:100px;

width:100px;

}

Try it »

There are more examples at the bottom of this page.


Property definition and usage

The width property sets the width of an element.

Note: The width property does not include padding, borders, and margins!

Default value: auto
Inherited: no
Version: CSS1
JavaScript syntax: object.style.width="50px"

Browser support

The numbers in the table indicate the first browser version that supports this property.

property
width 1.0 4.0 1.0 1.0 3.5

Attribute values

Value Description
auto Default value. The browser calculates the actual width.
length Defines the width using units such as px and cm.
% Defines a percentage width based on the width of the containing block (the parent element).
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 an element's width using a percentage value.


Related Articles

CSS Tutorial: CSS Dimension

CSS Tutorial: CSS Box model

CSS Reference Manual: height property