Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Use the minmax function to specify dynamically-sized tracks

    Rory SmithRory Smith

    Using minmax() is an amazingly useful way to specify boundaries for the smallest and largest size a grid track can be. Let’s find out how to apply it.



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson




    We have some mockup consisting of a container with two divs inside. Our container is display: grid with a 30px gap and taking up all the available height. Our grid items have a background-color. We want each of our divs to have their own column, so we're going to go down and set up some grid-template-columns. Let's say we wanted each one to be 100px wide. Now we have two 100px columns.

    Or we could also specify the minimum and maximum width of our columns using the minmax() function. Let's say we wanted them to be 100px at the very least and taking up all the available space at the most. We could say minmax(100px, auto) for the first column and the same for the second column. Now the columns take up all the available space, but they'll never get smaller than 100px.

    We could use a range of different width values in our minmax() functions. We could say that our first column should never be bigger than 200px. Now our second column is taking up the available space. We could use percentage values too. Now our first column never takes up less than 10 percent of the viewport.

    We could also use a flex value using the fr unit. We could say that our first column's max is 1fr and our second column's max is 4fr. Now they scale. Finally, we could use min-content and max-content. With this example, we've got some placeholder text in each of our columns. As we get further and further down on a small screen, we see some overflow in our first column.

    We could specify min-content as our minimum value in minmax(). Now we have no overflow because the minimum value is however much space is being taken up, in this case, by our text. If we were to use max-content, in this case the width of the div would be defined by however long the text is without it wrapping.