English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The width CSS attribute specifies the width of the content area of the element. This content does not include padding, border, or margin. Please refer toCSS box model.
The following table explains the usage and version history of this attribute, as well as the syntax of its use in JavaScript scripts.
Default value: | auto |
---|---|
Applies to: | All elements except replaced embedded elements, table rows, and row groups |
Inheritance: | No |
Animatable: | Yes.Please refer to Animation attribute. |
Version: | CSS 1,2,3 |
JavaScript syntax: | object.style.width="280px" |
The syntax of this attribute is as follows:
width: length | percentage | auto | initial | inherit
The following examples demonstrate how to use the width attribute.
p { width: 300px; background-color: #f0e68c; }Test to see‹/›
The following table describes the values of this attribute.
Value | Description |
---|---|
length | Specify the width as a length value, in units such as px, pt, cm, em, etc. Negative length values are not allowed. |
percentage | Specify the width as a percentage. The percentage is calculated relative to the width of the element's containing block. Negative percentage values are not allowed. |
auto | The browser will calculate the width of the specified element based on the values of other attributes. This is the default value. |
initial | Set this attribute to its default value. |
inherit | If specified, the associated elements adopt the width attribute value of their parent element. |
Browser compatibility, the numbers in the table below represent the minimum version number of browsers that support this attribute; all mainstream browsers support this attribute.
|
Please refer to the tutorials related to the following content:CSS Box Model,CSS dimensions.