CSS PROPERTIES
Expand All|Collapse All
CSS AT-RULES
SPONSORED LINKS

CSS width Property

Topic: CSS3 Properties Reference« Prev|Next »

Description

The width CSS property specifies the width of the content area of an element. This content does not include padding, borders, or margins. See the CSS box model.

The following table summarizes the usages context and the version history of this property.

Default value: auto
Applies to: All elements except non-replaced inline elements,
table rows, and row groups
Inherited: No
Animatable: Yes. See animatable properties.
Version: CSS 1, 2, 3

Syntax

The syntax of the property is given with:

width length | percentage | auto | initial | inherit

The example below shows the width property in action.

  • p {
  •     width: 300px;
  •     background-color: #f0e68c;
  • }

Property Values

The following table describes the values of this property.

Value Description
length Specifies the width as a length value in px, pt, cm, em, etc. Negative length values are not allowed.
percentage Specifies the width in percentage. The percentage is calculated with respect to the width of the element's containing block. Negative percentage values are not allowed.
auto The browser will calculate the width for the specified element on the basis of the values of other properties. This is default value.
initial Sets this property to its default value.
inherit If specified, the associated element takes the computed value of its parent element width property.

Browser Compatibility

The width property is supported in all major modern browsers.

Browsers Icon

Basic Support—

  • Firefox 1+
  • Google Chrome 1+
  • Internet Explorer 4+
  • Apple Safari 1+
  • Opera 4+

Further Reading

See tutorial on: CSS Box Model, CSS Dimension.

Related properties: max-width, min-width.

 
Close

Your Feedback:

 

We would love to hear from you! Please say something.