Width Property in CSS

Last Updated : 10 Aug 2026

The width belongings in CSS is used to specify an element's width. It indicates the element's content location width, omitting margins, borders, and padding. Units of dimension for the width property include pixels (px), probabilities (%), em devices, and different period devices.

Here's a basic example:

Another option is to use percentage values, which are determined in relation to the containing element's width:

Keep in mind that if padding, borders, or margins are applied, the width of belongings may not constantly be enough to decide an element's total width. In those situations, you need to take the field version into account and regulate the values correctly.

For instance, you might want to apply the container-sizing assets to set the element's standard width, which includes padding and borders:

The container-sizing: border-container; in the instance above, make certain that the width targeted consists of the width of the content as well as any padding and border widths.

CSS width values

ValueDescription
autoIt is a default value. it is used to calculate the width.
lengthIt is used to define the width in px, cm etc.
%It defines the width of the containing block in %.
initialIt is used to set the property to its default value.
inheritIt is used to inherit the property from its parent element.

Properties of width in CSS

1. Relative Units:

To grow the ability and responsiveness of your format, remember to use relative gadgets, including probabilities, em, or rem. A common approach for creating fluid layouts that trade in keeping with the figure box's length is to use possibilities.

2. Max-width and Min-width:

In addition to width, you can use the max-width and min-width properties to modify an element's behavior within specific length tiers. When designing responsive designs, this is useful.

3. Auto Value:

When an element is set to width: vehicle; it fills the to be had width, that's mainly useful for block-degree elements like div.

4. Using Flexbox and Grid:

In case you're making use of current format methods, which include Flexbox or Grid, you may only practice the width assets. You should use grid-template-columns in Grid and flex-basis in Flexbox.

5. Media Queries:

Media queries are not unusual for devices used in responsive layout to use diverse styles in line with the device's specs. The width of factors may be changed to deal with various screen sizes.

These are just a few times the extraordinary CSS situations in which the width assets can be applied. It's an important feature for dealing with how factors are arranged and sized on a webpage.

CSS Width Example: width in px

Output:

CSS Width

CSS Width

The height and width of this paragraph is 150px.

This is a paragraph.

CSS Width Example: width in %

The percent width is a measurement unit for the containing block. It is great for images.

Output:

CSS Width

CSS Width 

CSS Width

Note: You can also use the "min-width" and "max-width" property to control the size of image.


Next TopicCSS Word Wrap