Table of contents
- 1. Summary
- 2. Syntax
- 2.1. Values
- 3. Examples
- 4. Notes
- 5. Specifications
- 6. Browser compatibility
- 6.1. See also
« CSS « CSS Reference
Summary
The width CSS property specifies the width of the content area of an element. The content area is inside the padding, border, and margin of the element.
- Initial value
:
auto - Applies to: block level and replaced elements
- Inherited : no
- Percentages: refer to the width of the containing block
- Media:
visual - Computed value
: the percentage or
autoas specified or the absolute length
Syntax
width: <length> | <percentage> | auto | max-content | min-content | fit-content | available
Values
- <length>
- See
<length>for possible units. - <percentage>
- Specified as a
<percentage>of containing block's width. auto- The browser will calculate and select a width for the specified element.
max-contentExperimental-
New in Firefox 3
The intrinsic preferred width. WebKit implements an earlier version of this value, under the name
intrinsic. [1] min-contentExperimental- New in Firefox 3 The intrinsic minimum width.
availableExperimental- New in Firefox 3 The containing block width minus horizontal margin, border and padding.
fit-contentExperimental-
New in Firefox 3
The larger of:
- the intrinsic minimum width
- the smaller of the intrinsic preferred width and the available width
Examples
table { width: 100%; }
img { width: 200px; }
form { width: auto; }
p { width: 40em; }
p { background: gold }
The Mozilla community produces a lot of great software.
p { background: lightgreen;
width: intrinsic; /* Safari/WebKit uses a non-standard name */
width: -moz-max-content; /* Firefox/Gecko */
}
The Mozilla community produces a lot of great software.
p { background: lightblue; max-width: -moz-min-content; }
The Mozilla community produces a lot of great software.
Specifications
Browser compatibility
| Browser | Lowest Version | intrinsic width | intrinsic minimum width | ||
|---|---|---|---|---|---|
| Internet Explorer | 4.0 | --- | --- | --- | --- |
| Firefox (Gecko) | 1.0 (1.0) | 3.0 (1.9) | -moz-max-content | 3.0 (1.9) | -moz-min-content |
| Opera | 3.5 | --- | --- | --- | --- |
| Safari (WebKit) | 1.0 (85) | 2.0 (412) ? | intrinsic | --- | --- |
See also
box model, height
, box-sizing
, min-width
, max-width
Mozilla Developer Network