Hi, I'm Jacob. Enjoying devFlipCards? Buy me a coffee

6. What units can you use in CSS to specify text size?

You can use various units to specify text size, such as:

  • px (pixels): fixed unit, independent of resolution.
  • em: relative unit, dependent on the font size of the parent element.
  • rem: relative unit, dependent on the font size of the root element (html).
  • %: percentage value relative to the parent element.
  • vw (viewport width): percentage of the viewport's width.
  • vh (viewport height): percentage of the viewport's height.
/* Examples */ h1 { font-size: 20px; /* Pixels */ } h2 { font-size: 2em; /* Em - 2 times the font size of the parent element */ } h3 { font-size: 1.5rem; /* Rem - 1.5 times the font size of the root element */ } h4 { font-size: 150%; /* Percentage */ } h5 { font-size: 10vw; /* Viewport width */ }
Struggling to find common date to meet with your friends? Try our new tool
commondate.xyz