Width

Category:CSS Properties

Width

The width property specifies the width of the content area of an element. The width of an element does not include padding, borders, or margins. Width can be defined in percent of the containing block, pixels, cm, etc.

Examples

Width as a percentage

Set the width of an <img> element using a percent value.

img {
  width: 50%;
}

Width in pixels

Setting the width of a <p> element to 300 pixels.

p {
  width: 300px;
}

Syntax

width: value;

Tips

  • The width property does not include padding, borders, or margins.
  • The default value of the width is auto: The element will automatically adjust its width to allow its content to be displayed correctly.

Additional Information

For more information, see http://www.w3schools.com/cssref/pr_dim_width.asp

Found a bug in the documentation? Let us know at documentation@code.org