Lesson 2 of 8
Type that adapts to the screen
- 12 min
- 5 checks
- 3 hints
- Go to task
Goal
One size that scales with clamp
Explanation
A heading that suits a large screen is far too big on a phone. The usual fix is three @media queries, one per size, and then you find that the size jumps suddenly whenever you cross from one query to the next.
clamp(min, preferred, max) solves this in one line. You give it a minimum, a maximum, and a value in the middle that follows the screen width in vw, and the browser scales smoothly between the two limits, with no jumps and no queries.
Make sure the middle value includes a relative unit (rem alongside vw). Otherwise, anyone who needs bigger text won't be able to enlarge it.
Your task
Use clamp to make the size of h1 scale between 28 and 56 pixels.
Checks
5 checks- h1 is at least 28 pixels
- h1 is at most 56 pixels
- The size is written with clamp()
- The changing part follows the screen width (vw)
- clamp has a relative part that keeps zoom working (rem or em)