Academy / Advanced Level: HTML and CSS

Advanced Responsive Web Design Techniques

Using CSS clamp() for Fluid Sizing

The clamp() function allows you to set a responsive range for any CSS property, ensuring that values dynamically scale between a minimum and maximum value. This is useful for fluid typography, margins, padding, and more.

Example: Fluid Typography with clamp()

h1 {
font-size: clamp(1.2rem, 2vw + 1rem, 2.5rem); /* Min size: 1.2rem, max size: 2.5rem */
}
  • The font size will start at 1.2rem on smaller screens and gradually increase to 2.5rem on larger screens.