0
0
SASSmarkup~10 mins

Responsive grid with breakpoints in SASS - Browser Rendering Trace

Choose your learning style9 modes available
Render Flow - Responsive grid with breakpoints
Read HTML grid container
Read grid items
Parse SASS variables and mixins
Compile SASS to CSS
Apply CSS grid styles
Apply media queries for breakpoints
Calculate grid layout per viewport width
Paint grid and items
Composite final layout
The browser reads the HTML grid container and items, compiles the SASS code into CSS including media queries for breakpoints, then applies the grid layout styles. It recalculates layout when viewport size changes to adapt the grid responsively.
Render Steps - 3 Steps
Code Added:display: grid; gap: 1rem; grid-template-columns: repeat(1, 1fr);
Before
[grid-container]
  [1]
  [2]
  [3]
  [4]
After
[grid-container]
  [1]
  [2]
  [3]
  [4]
The container becomes a grid with one column, so items stack vertically with spacing between them.
🔧 Browser Action:Creates grid formatting context, calculates single column layout, triggers reflow
Code Sample
A grid container with 4 items that shows 1 column on small screens, 2 columns on medium screens, and 4 columns on large screens, with spacing and styling for clarity.
SASS
<section class="grid-container">
  <div class="grid-item">1</div>
  <div class="grid-item">2</div>
  <div class="grid-item">3</div>
  <div class="grid-item">4</div>
</section>
SASS
$gap: 1rem;
$columns-small: 1;
$columns-medium: 2;
$columns-large: 4;

.grid-container {
  display: grid;
  gap: $gap;
  grid-template-columns: repeat(#{$columns-small}, 1fr);

  @media (min-width: 600px) {
    grid-template-columns: repeat(#{$columns-medium}, 1fr);
  }

  @media (min-width: 900px) {
    grid-template-columns: repeat(#{$columns-large}, 1fr);
  }
}

.grid-item {
  background-color: #a0c4ff;
  padding: 1rem;
  text-align: center;
  border-radius: 0.5rem;
}
Render Quiz - 3 Questions
Test your understanding
After applying step 2, how are the grid items arranged visually?
AFour columns in one row
BOne column stacked vertically
CTwo columns and two rows
DItems overlap each other
Common Confusions - 3 Topics
Why do grid items stack vertically on small screens even though I set multiple columns?
Because the default grid-template-columns is set to one column for small screens (step 1). The multiple columns only apply inside media queries at larger widths (steps 2 and 3).
💡 Grid columns change only when media queries activate; before that, items stack.
Why does the grid suddenly change layout when I resize the browser?
Because media queries detect viewport width changes and apply different grid-template-columns values (steps 2 and 3), causing the grid to reflow with new columns.
💡 Media queries trigger layout changes at breakpoints.
Why is there space between grid items but no margin on the items themselves?
The gap property on the grid container adds spacing between items without needing margins on each item (step 1). This keeps spacing consistent and easier to manage.
💡 Use gap on grid container for spacing, not margins on items.
Property Reference
PropertyValue AppliedAxis/DirectionVisual EffectCommon Use
displaygridN/ACreates grid container for childrenLayout container
gap1remBothAdds space between grid itemsSpacing between items
grid-template-columnsrepeat(1, 1fr)HorizontalOne column layout, items stacked verticallySmall screens
grid-template-columnsrepeat(2, 1fr)HorizontalTwo equal columns, items arranged in rowsMedium screens
grid-template-columnsrepeat(4, 1fr)HorizontalFour equal columns, items in one rowLarge screens
@media (min-width: ...)N/AN/AApplies styles only at certain viewport widthsResponsive design
Concept Snapshot
Responsive grid uses CSS grid with media queries. Set grid-template-columns for different screen widths. Use gap for spacing between items. Media queries change columns at breakpoints. Items rearrange automatically as viewport changes.