CSS Units

Level : Intermediate
Mentor: Shailendra Chauhan
Duration : 00:01:40

CSS Unit cm:

Represents length in centimeters.

Example:

.element {
  width: 5cm;
}

CSS Unit mm:

Represents length in millimeters.

Example:

.element {
   margin: 10mm;
}

CSS Unit in:

Represents length in inches.

Example:

.element {
  font-size: 1in;
}

SS Unit px:

Represents pixels (screen pixels).

Example:

.element {
  border-width: 2px;
}

CSS Unit pt:

Represents points (1/72nd of an inch, typically used for print).

Example:

.element {
  font-size: 12pt;
}

CSS Unit pc:

Represents picas (1/6th of an inch, used in print).

Example:

.element {
  line-height: 2pc;
}

CSS Unit em:

Represents font size relative to the parent element's font size.

Example:

.element {
  font-size: 1.5em;
}

CSS Unit ex:

Represents font size relative to the height of the lowercase 'x' character.

Example:

.element {
  line-height: 1.2ex;
}

CSS Unit ch:

Represents width relative to the width of the '0' character.

Example:

.element {
  width: 10ch;
}

CSS Unit rem:

Represents font size relative to the root element's font size.

Example:

.element {
  font-size: 1.2rem;
}

CSS Unit vw:

Represents a percentage of the viewport width.

Example:

.element {
  width: 50vw;
}

CSS Unit vh:

Represents a percentage of the viewport height.

Example:

.element {
  height: 30vh;
}

CSS Unit vmin:

Represents a percentage of the smaller dimension of the viewport (width or height).

Example:

.element {
  font-size: 5vmin;
}

CSS Unit vmax:

Represents a percentage of the larger dimension of the viewport (width or height).

Example:

.element {
  padding: 3vmax;
}

CSS Unit %:

Represents a percentage of the parent element's value.

Example:

.element {
  width: 50%;
}
Self-paced Membership
  • 22+ Video Courses
  • 800+ Hands-On Labs
  • 400+ Quick Notes
  • 55+ Skill Tests
  • 45+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Still have some questions? Let's discuss.
CONTACT US
Accept cookies & close this