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.


    Refer to fractions of available space with the fr unit

    Rory SmithRory Smith

    There’s an unfamiliar fr unit pertinent to CSS Grid, which allows us to specify a fractional unit of space. Let’s see 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 five boxes inside a container here. Let's set display: grid on our container. We'll make it take up all the available height. We'll make the boxes a little bit more visible. We'll set a background-color and a font-size. We'll split up our items a bit with a gutter.

    By default, all of our boxes take up the available space, so they're all equal heights. Let's say we wanted to make box a and box e smaller than the others. We'll set up some grid-template-rows. We're going to use the fr unit to tell each item how much space to take up.

    A will take up one fr unit. B, c, and d can all take up three frs. E can also take up one fr. A and e are smaller than the other boxes. This is a nice, easy way to denote that we want to use all the available space without having to rely on absolute values.

    Fr units refer to the available space. In this case, the available space is the entire vertical space. We can mix that up with values that aren't frs. For example, we could say that we want a to take up 20px, b to take up 30, and c to take up 40. Then let's say we wanted d to be a lot bigger than e. We could say 2fr 1fr.

    A, b, and c have absolute values, whereas d and e are simply taking up the available space because they have fr values. If we were to change d to 3fr, a, b, and c stayed in the same place, but d got bigger, and e moved down a bit. Fr values only affect the available space.