width property sets the width of an element.
The width property doesn't include padding, borders, or margins. It sets the width of the area inside the padding, border, and margin of the element.
CSS width values
width property can have the following values:
autoThis is default. The browser calculates the width
lengthDefines the width in px, cm etc.
%Defines the width in percent of the containing block
initialSets the width to its default value
inheritThe width will be inherited from its parent value
Remember that the
width property doesn't include padding, borders, or margins! It sets the width of the area inside the padding, border, and margin of the element!
max-width property defines the maximum width of an element.
If the content is larger than the maximum width, it will automatically change the width of the element.
If the content is smaller than the maximum width, the
max-width property has no effect.
This prevents the value of the
width property from becoming larger than
max-width. The value of the
max-width property overrides the width property.