Responsive Padding Without a Single Media Query
When I first learned responsive design, media queries were my answer to everything. Narrow screen? Add a breakpoint and shrink the padding. Wider screen? Add another one. Before long, a simple card needed three or four rules just to keep its spacing sensible.
Then I came across a much neater approach, which I now use in my CSS Impress demo:
p {
padding: min(3em, 9%);
}
That single line does the job of several media queries. The min() function takes a list of values and uses whichever is smallest at that moment, so the padding is never larger than either option.
The trick lies in how the two units behave. 3em is based on the font size, so it stays the same however wide the screen is. 9% is based on the width of the parent element, and it is worth remembering that this applies to the top and bottom padding too, not just the sides.
On a wide screen, 9% of the container is a large number, so 3em wins and the padding stays comfortably capped. As the screen narrows, 9% eventually becomes the smaller value and takes over, shrinking the padding smoothly so the text keeps as much room as possible. With 16px text, the switch happens when the container is around 533px wide, and there is no sudden jump at a breakpoint, just a gradual change.
If you also want a minimum, clamp() takes it a step further: padding: clamp(1em, 9%, 3em) sets a floor, a preferred value and a ceiling.
Media queries still have their place, especially for bigger layout changes. But for spacing, letting the browser do the maths with min() and clamp() keeps my stylesheets shorter and far easier to maintain.