Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

CSS width property


May 06, 2021 CSS Reference Manual


Table of contents


CSS width property

Description of property definition and use

The width property sets the width of the element.

Note: width properties do not include padding, borders, and margins!

Default: auto
Inherited: no
Version: CSS1
JavaScript syntax: object .style.width="50px"

The property value

Value Describe
auto The default. The browser calculates the actual width.
length Define the width in px, cm, and other units.
% Defines the percentage width based on the width of the containing block (parent element).
inherit Specifies that the value of the width property should be inherited from the parent element.

Browser support

The numbers in the table support the first browser version number of the property.

Attributes
width 1.0 4.0 1.0 1.0 3.5

Set the height and width of a paragraph:

p.ex
{
height:100px;
width:100px;
}

Try it out . . .

CSS width property

More instances

Use percentages to set the width of an element
This example shows how to use a percentage value to set the width of an element.


Related articles

CSS tutorial: CSS Dimension

CSS tutorial: CSS Box model

CSS Reference Manual: Height Properties