#1 Data Analytics Program in India
₹2,499₹1,499Enroll Now
4 min read
Question 23 of 49easy

What are CSS Units?

Understanding px, em, rem, %, vh, vw and more.

What You'll Learn

  • Absolute vs relative units
  • When to use each
  • Responsive units

Absolute Units

UnitDescription
pxPixels
ptPoints (print)
cm, mm, inPhysical units

Relative Units

UnitRelative To
emParent font-size
remRoot font-size
%Parent element
vw1% of viewport width
vh1% of viewport height
vminSmaller of vw/vh
vmaxLarger of vw/vh

Examples

styles.cssCSS
html { font-size: 16px; }

.element {
  font-size: 1.5rem; /* 24px */
  padding: 1em; /* relative to own font-size */
  width: 50%; /* half of parent */
  height: 100vh; /* full viewport height */
  min-height: 50vmin; /* 50% of smaller dimension */
}