CSS Grid Layout has revolutionized modern web design by making complex layouts more manageable and responsive. While properties like grid-template-rows
and grid-template-columns
are commonly used, developers sometimes come across properties like grid-row-align
and grid-column-align
.
In this blog post, we’ll explore whether these properties are valid, what you’re actually looking for, and how to achieve alignment in CSS Grid properly.
🧠 Quick Clarification: grid-row-align
and grid-column-align
Are Not Standard CSS Properties
First, let’s clear up a common misconception:
🚫
grid-row-align
andgrid-column-align
are not official or valid CSS properties.
If you’ve encountered these in code or documentation, it’s likely a mistake or confusion with the actual alignment properties used in CSS Grid.
So, what should you be using instead?
✅ The Correct Grid Alignment Properties
To align grid items along rows and columns, CSS Grid provides these standard properties:
1. justify-items
/ justify-self
Used to align items horizontally (along the row axis).
2. align-items
/ align-self
Used to align items vertically (along the column axis).
3. place-items
and place-self
Shorthand for align-*
and justify-*
combinations.
🔧 Examples: Proper Alignment in CSS Grid
HTML
<div class="grid-container">
<div class="grid-item">Item 1</div>
<div class="grid-item">Item 2</div>
<div class="grid-item">Item 3</div>
</div>
CSS
.grid-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: 150px;
/* Align all items */
justify-items: start; /* Align horizontally to the left */
align-items: center; /* Align vertically to the center */
}
.grid-item {
background-color: #dfefff;
padding: 1rem;
border: 1px solid #ccc;
}
Explanation
justify-items: start;
aligns the content of each grid cell to the left.align-items: center;
vertically centers the content within each row.
If you want to align just one item, use justify-self
and align-self
on that item:
.grid-item:nth-child(2) {
justify-self: end; /* Align to the right */
align-self: start; /* Align to the top */
}
🧩 Shorthand: place-items
and place-self
Instead of writing:
align-items: center;
justify-items: start;
You can write:
place-items: center start;
Or for a single item:
.grid-item {
place-self: end center;
}
❓ So Where Did grid-row-align
Come From?
It might be:
- A non-standard extension or typo
- Misunderstood from older specs
- Confused with
align-self
oralign-items
Always refer to MDN Web Docs or the official W3C specification for up-to-date and accurate property references.
✅ Summary
Desired Effect | Use This Property |
---|---|
Align all items horizontally | justify-items |
Align all items vertically | align-items |
Align one item horizontally | justify-self |
Align one item vertically | align-self |
Combine both directions | place-items , place-self |
💬 Final Thoughts
While grid-row-align
and grid-column-align
might look plausible, they’re not valid CSS. Instead, master the real alignment tools in CSS Grid: align-*
, justify-*
, and place-*
.
With these, you can build precise, responsive layouts with ease and confidence.