CSS Height and Width || Bcis Notes

CSS Height and Width

Programmers can use the height and width properties to change the height and width of specific elements. In order for their dimensions to be altered, the display property value of these elements must be set to block or inline-block. These properties do not include padding, borders, or margins. It sets the height/width of the area inside the padding, border, and margin of the element.

CSS height/width Values
The height and width properties may have the following values:

  • auto – This is the default. The browser calculates the height and width
  • length – Defines the height/width in px, cm etc.
  • % – Defines the height/width in percent of the containing block
  • initial – Sets the height/width to its default value
  • inherit – The height/width will be inherited from its parent value





Setting max-width
The max-width property is used to set the maximum width of an element. The max-width can be specified in length values, like px, cm, etc., or in percent (%) of the containing block, or set to none (this is the default. This means that there is no maximum width). The browser then adds a horizontal scrollbar to the page. Using max-width instead, in this situation, will improve the browser’s handling of small windows.

Tip: Drag the browser window to smaller than 500px wide, to see the difference between the two divs!






All CSS Dimension Properties :


You may also like: CSS Padding

Leave a Comment

Your email address will not be published. Required fields are marked *