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 */ }
devFlipCards 2024

Do you accept cookies?

Cookies are small amounts of data saved locally on you device, which helps our website - it saves your settings like theme or language. It helps in adjusting ads and in traffic analysis. By using this site, you consent cookies usage.