CSS Grid Carrot Patch teaches CSS grid layout using a five-by-five vegetable plot. Some squares hold carrots, some hold weeds, and you write real CSS that drops a patch of water or poison exactly where it belongs. Since the garden is a live grid container, CSS Grid Carrot Patch moves the patch as you type, so line numbers and spans click into place far faster than they do from a diagram.

Working the garden

Each level has a short lesson, a code box and the plot. Most of the stylesheet is already there, and you add the missing declarations. When the water or poison covers exactly the right squares, the Next button lights up. Press it, the plants change to show they have been treated, and a new level loads.

You can open the level counter at any time to jump around. Solved levels are marked, and the property names highlighted in each lesson show a list of the values they accept.

CSS Grid Carrot Patch Controls

Controls for CSS Grid Carrot Patch
ActionKeyboardMouseTouch
Type CSSType in the code box—Tap the code box and use the on-screen keyboard
Submit a correct answerEnter on the last line, or Ctrl + EnterClick "Next" once it lights upTap "Next"
Pick a level—Click the level counter, then a level number, or use the side arrowsTap the level counter, then a level number
Read about a property—Point at a highlighted property name in the instructions—

The path through 28 levels

  • Placing by line: grid-column-start and grid-column-end, plus negative line numbers.
  • Sizing by span: span 3 instead of an end line.
  • Shorthands: grid-column, grid-row and the four-value grid-area.
  • Overlap: two patches that cover some of the same squares.
  • Reordering: the order property for automatically placed items.
  • Building the grid itself: grid-template-columns, grid-template-rows and grid-template, with percentages, pixels, repeat() and fr units.

The math in a grid

CSS grid is a coordinate system. Lines work like the tick marks on a number line, and a patch is defined by where it starts and stops on two axes. Saying that a patch runs from line 2 to line 5 means it covers three cells, the same kind of reasoning as finding the length of a segment from 2 to 5.

The fr unit is a lesson in ratios. In 1fr 3fr, leftover space is split into four equal parts, with one going to the first column and three to the second. Fixed widths are taken out first, so you also practice subtracting before you divide.

Gardening tips

  1. Count lines, not squares. Covering columns 2 to 4 means grid-column: 2 / 5.
  2. Use span whenever you know the size but the start is already set.
  3. Write grid-area values in the order row start, column start, row end, column end.
  4. For fr levels, subtract any fixed sizes first, then share what is left.
  5. Point at highlighted property names when you forget what values they take.

Practical Notes for Players

On narrow screens the garden and the editor stack in one column, so you can play on a tablet with its on-screen keyboard, though a computer makes the hints easier to use. If you have not tried it, Flexbox Lily Pond covers the one-dimensional layout tool that grid builds on, and CSS Diner teaches the selectors that point styles at elements.

Tested and updated: