CSS width Property
Description
The width property controls the horizontal size an element takes in layout — it determines the size of the element’s content box (subject to the box model) and therefore affects how much inline space the element occupies and how its children are laid out. In normal flow block-level elements the declared horizontal size is a primary driver of reflow: it influences line wrapping of text, the calculation of percentage-based sizes for descendants, and how neighboring elements flow around or alongside the box. Because an element’s used width is one of the fundamental layout inputs, changes to it typically trigger reflow and repaint of the document.
How that horizontal value is interpreted depends on the box model and surrounding properties. The interplay with the box-sizing model determines whether padding and border are counted inside the specified box or added outside it; the visual outer size is then influenced by padding, border, and outer spacing such as margin. Percentages and relative measurements are resolved against the containing block, so changing an ancestor’s size cascades into new used widths for descendants. Because margins can collapse or shift in block formatting contexts, the way outer spacing interacts with available width can be non‑trivial.
Width never acts in isolation — constraints and overflow rules can alter the final rendered result. Specified constraints from min-width and max-width will clamp the computed width, and when content does not fit the established width the element’s overflow handling (controlled by overflow) decides whether content is clipped, scrollable, or allowed to expand other layout factors. Intrinsic sizing and aspect relationships (for replaced elements and elements with intrinsic ratios) can also affect the used width; the aspect-ratio concept is often used to preserve proportions when only one dimension is constrained.
Different layout contexts compute and use width differently. Inline-level layout, floats and absolutely positioned elements follow different sizing rules: floats use a shrink-to-fit calculation and are affected by the element’s float behavior, absolutely positioned elements are taken out of normal flow and interact with offsets when position is non‑static, and flex or grid items participate in their container’s distribution algorithms (with flex items often influenced by flex-basis). For replaced elements like images and videos, intrinsic dimensions and available space (including the element’s declared width and computed height) combine to determine the final painted size. Understanding how width interacts with these contexts is essential for predictable, robust layout.
Definition
- Initial value
- auto
- Applies to
- All elements except non-replaced inline elements, table rows, and row groups
- Inherited
- No
- Computed value
- Percentage or absolute length
- Animatable
- Yes
- JavaScript syntax
- object.style.width
Interactive Demo
Syntax
width: <length> | <percentage> | auto
Values
- <length>Specifies the width of the content area using a length unit.
- <percentage>Integer, followed by a %. The value is a percentage of the width of the parent object, whether or not it is specified explicitly. Negative values are not allowed.
- autoThe width depends on the values of other properties. See the sections below.
- border-boxIf border-box is used, the length or percentage defined will be applied to the element's border box.
- content-boxIf content-box is used, the length or percentage defined will be applied to the element's content-box.
- autoIf auto is set for the elements width, the browser will determine the width for the element.
- max-contentThe intrinsic preferred width
- min-contentThe intrinsic minimum width
- availableThe containing block width minus horizontal margin, border, and padding
- fit-contentThis will be either the large of the minimum width or the smaller of the preferred width and the available width
Example
Browser Support
The following information will show you the current browser support for the CSS width property. Hover over a browser icon to see the version that first introduced support for this CSS property.
This property is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 1st January 2026
