Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    { }CSS

    Styling foundations

    • What is CSS?
    • Cascade and specificity
    • Selectors and element states
    • Colours and text

    Boxes and sizing

    • Padding, border and margin
    • Units and flexible sizing
    • Overflow and image fitting

    Layout and responsiveness

    • Flexbox
    • CSS Grid
    • Positioning and stacking
    • Responsive design
    • Container-based responsiveness

    Design values, direction and motion

    • CSS custom properties and functions
    • Logical properties for RTL and LTR
    • CSS transitions and transforms
    • Keyframes and bounded animation
    • Project: a product card
    CSS

    Layout and responsiveness · Lesson 9 of 17

    CSS Grid

    Rows and columns made easy for whole-page layouts.

    8 minutes2 games

    display: grid with grid-template-columns splits space into columns. The fr unit means “a share of the free space”: 1fr 1fr 1fr is 3 equal columns. repeat(3, 1fr) is the same, shorter.

    HTML
    <style>
      .gallery {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
      }
      .gallery div {
        background: #e0e7ff;
        padding: 24px;
        text-align: center;
        border-radius: 8px;
      }
    </style>
    
    <div class="gallery">
      <div>1</div><div>2</div><div>3</div>
      <div>4</div><div>5</div><div>6</div>
    </div>
    .grid { grid-template-columns: 1fr 1fr; gap: 12px; }

    Try different column proportions and gaps.

    Important

    fr distributes available space; intrinsic minimum sizes can affect visible proportions. minmax(0, 1fr) helps when long content expands a track.

    Interview question

    How do gap and margin differ?

    Flexbox for one row of things (like a menu); Grid when you have rows and columns together (like a gallery).

    Quick question

    What does grid-template-columns: 2fr 1fr mean?

    Exercise

    Make .grid with 4 equal columns.

    HTML
    <style>
      .grid {
        
      }
    </style>
    <div class="grid"><p>1</p><p>2</p><p>3</p><p>4</p></div>
    

    Learn more from

    • MDN: CSS referencedeveloper.mozilla.org
    • web.dev: gridweb.dev

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    PreviousFlexboxNextPositioning and stacking
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.