Docs/CSS/Units

CSS Units

Absolute

  • px — pixel (paling umum)

Relative

  • em — relatif dari font-size parent
  • rem — relatif dari font-size root (html)
  • % — persentase dari parent
  • vw / vh — persentase dari viewport width/height
  • vmin / vmax — viewport terkecil/terbesar

Rekomendasi

  • Font-size: gunakan rem
  • Spacing: gunakan rem atau px
  • Layout width: gunakan % atau fr
style.css
Try It →
<div>
  <div><strong>16px</strong> — fixed pixel</div>
  <div><strong>1.2rem</strong> — relative to root</div>
  <div><strong>1.2em</strong> — relative to parent</div>
  <div><strong>width: 75%</strong></div>
  <div><strong>width: 50%</strong></div>
</div>