Ask any question about CSS here... and get an instant response.
Post this Question & Answer:
How can I use CSS clamp() to create responsive font sizes?
Asked on Jan 29, 2026
Answer
The CSS `clamp()` function allows you to set a responsive font size that adapts between a minimum and maximum value based on the viewport size. This ensures that your text remains legible on all devices.
<!-- BEGIN COPY / PASTE -->
<style>
.responsive-text {
font-size: clamp(1rem, 2.5vw, 2rem);
}
</style>
<p class="responsive-text">This text size is responsive!</p>
<!-- END COPY / PASTE -->Additional Comment:
- The `clamp()` function takes three arguments: a minimum value, a preferred value (often based on viewport width), and a maximum value.
- In the example, `1rem` is the smallest size, `2.5vw` is the preferred size that scales with the viewport, and `2rem` is the largest size.
- This method ensures that the font size remains within a reasonable range, providing a balance between flexibility and control.
- Using `clamp()` is particularly useful for creating typography that adapts gracefully to different screen sizes without media queries.
Recommended Links:
