CSS Height & Width

The height and width properties are used to define the dimensions of an element in terms of height and width.


CSS Height & Width Details


Height Property (height: value;):

  • Purpose : Specifies the height of an element.

  • Values : Accepts various units such as pixels (px), percentages (%), viewport units (vh for viewport height), em, rem, etc.


Width Property (width: value;):

  • Purpose : Specifies the width of an element.

  • Values : Accepts various units such as pixels (px), percentages (%), viewport units (vh for viewport height), em, rem, etc.


Max Height Property (max-height: value;):

Restricts the element’s height from exceeding the specified maximum value.

  • Purpose : Sets the maximum height that an element can have.

  • Values : Accepts various units such as pixels (px), percentages (%), viewport units (vh for viewport height), em, rem, etc.


Min Height Property (min-height: value;):

Ensures that the element’s height doesn’t shrink below the specified minimum value.

  • Purpose : Sets the minimum height that an element can have.

  • Values : Accepts various units such as pixels (px), percentages (%), viewport units (vh for viewport height), em, rem, etc.


Max Width Property (max-width: value;):

Restricts the element’s width from exceeding the specified maximum value.

  • Purpose : Specifies the maximum width that an element can have.

  • Values : Accepts various units such as pixels (px), percentages (%), viewport units (vh for viewport height), em, rem, etc.


Min Width Property (min-width: value;):

Ensures that the element’s width doesn’t shrink below the specified minimum value.

  • Purpose : Specifies the minimum width that an element can have.

  • Values : Accepts various units such as pixels (px), percentages (%), viewport units (vh for viewport height), em, rem, etc.