CSS Width

The CSS width property is used to set the width of the content area of an element.

It does not include padding borders or margins. It sets width of the area inside the padding, border, and margin of the element.

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.

CSS Width Example: width in px

Test it Now

Output:


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.

Test it Now

Output:



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

Next TopicCSS Word Wrap




Latest Courses