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.


    Re-order the appearance of grid items using the order property

    Rory SmithRory Smith

    As with flex items, we can set an order value on grid items. Let’s see how this affects the DOM and the appearance of our grid.



    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




    In this example, we have five grid items inside a container. The container's a display grid with a 10-pixel gutter and it's taking up all the available height. Each grid item is being displayed in a linear way as per the way we've described it in our markup.

    In some instances, we might find that we want to keep the order specified in our markup, but we might want to reorder how each item looks on the page. For example, we might want to reorder the elements on a mobile layout differently to how they look on tablet layout.

    By default, each element has an order value of 0If we were to go under the hood here and inspect each element, here's the order value and by default it's 0Each one of these values has an order value of 0If we were to target one of our grid items -- let's say the second one -- and we gave it order one, then it moves right to the end. The reason is that everything else has an order of 0and 2 has an order of 1.

    We could also use minus values here. Let's target the fifth one. Say order-1 and it puts it to the start. Note that the order in the dom hasn't changed at all from how we specified it in our markup.

    Also, note that if we specify grid column and grid row values for our grid items they will also reorder the elements. In this case, if we took off our order property and we said grid row 1, we'd get the same result.