This content originally appeared on Manuel Matuzović - Web development blog and was authored by Manuel Matuzović
The clamp()
function defines a minimum value, a preferred value, and a maximum value.
A quick recap of min() and max() before we talk about clamp()
:
We can use the min()
function to define a maximum value for a property. It's the maximum value we define because in the list of provided parameters, min()
will always pick the smallest value. For example, width: min(700px, 90%)
is always 700px or less, which means that the maximum width is 700px.
div {
width: min(90%, 700px);
}
div {
width: max(300px, 90%);
}
div {
width: max(300px, min(90%, 700px));
}
div {
width: clamp(300px, 90%, 700px);
}
The width
of the <div>
is 90% with a minimum width of 300px and maximum width of 700px. It's basically a shorter way of writing:
div {
width: 90%;
min-width: 300px;
max-width: 700px;
}
This content originally appeared on Manuel Matuzović - Web development blog and was authored by Manuel Matuzović

Manuel Matuzović | Sciencx (2022-11-08T09:38:54+00:00) Day 32: the clamp() function. Retrieved from https://www.scien.cx/2022/11/08/day-32-the-clamp-function/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.