AI CSS Place Items — Master Grid and Flexbox Alignment
Centering a div has been a running joke in web development for decades. The truth is, CSS alignment is genuinely confusing — not because the properties are complex, but because there are too many of them. Between align-items, justify-items, align-content, justify-content, align-self, and justify-self, developers spend more time remembering which property does what than actually writing layout code.
The place-* shorthand properties fix this. They combine the align and justify axes into single declarations, cutting your alignment code in half. An AI CSS Place Items Generator lets you experiment with every combination visually and see the result in real time.
The Three Place Shorthands
CSS provides three place-* properties, each combining its align and justify counterparts:
place-items
/* place-items: <align-items> <justify-items> */
.grid {
display: grid;
place-items: center;
}
This single line replaces align-items: center and justify-items: center. When you provide one value, it applies to both axes. Two values set the block (vertical) axis first, then the inline (horizontal) axis:
.grid {
display: grid;
place-items: start center; /* top-center */
}
place-content
/* place-content: <align-content> <justify-content> */
.grid {
display: grid;
grid-template-columns: repeat(3, 200px);
place-content: center space-between;
}
While place-items aligns items within their grid cells, place-content aligns the grid tracks within the container. This matters when your grid tracks don't fill the entire container — the extra space needs to go somewhere.
place-self
/* place-self: <align-self> <justify-self> */
.special-item {
place-self: end center;
}
This overrides the container's alignment for a single item. Useful for breaking one element out of the grid's default alignment without affecting siblings.
Visualize CSS alignment instantly
AI-powered place-items generator with interactive Grid and Flexbox preview. See every alignment combination in real time.
Try AI CSS Place Items Generator →The Perfect Centering Pattern
The most famous use of place-items is the two-line centering trick:
.container {
display: grid;
place-items: center;
min-height: 100vh;
}
That's it. Any child element is perfectly centered both horizontally and vertically. No position: absolute, no transform: translate(-50%, -50%), no flexbox gymnastics. This works because Grid creates a single implicit cell that fills the container, and place-items: center centers the child within that cell.
Compare this to the old approach:
/* The old way — 6 lines */
.container {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
}
/* The modern way — 3 lines */
.container {
display: grid;
place-items: center;
min-height: 100vh;
}
place-items in Grid Layouts
Dashboard Card Grid
.dashboard {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
gap: 20px;
place-items: stretch; /* default — cards fill their cells */
}
.stat-card {
display: grid;
place-items: center; /* center the stat number and label */
padding: 32px;
background: #12121a;
border-radius: 12px;
}
The outer grid uses stretch (the default) so cards fill their cells completely. Each card uses place-items: center internally to center its content. This two-level grid pattern is common in dashboard designs.
Asymmetric Alignment
.feature-grid {
display: grid;
grid-template-columns: 1fr 1fr;
place-items: center start;
gap: 40px;
}
.feature-grid .icon {
place-self: center; /* override: center the icon */
}
Items are vertically centered but left-aligned horizontally. The icon overrides this with place-self: center to center itself in its cell. Mixing container-level and item-level alignment gives you precise control.
place-items with Flexbox
The place-items property works with Flexbox too, though with a caveat: justify-items has no effect in flex containers (use justify-content instead). So in Flexbox, place-items effectively only controls the cross-axis alignment:
.flex-container {
display: flex;
flex-wrap: wrap;
place-items: center; /* only align-items: center takes effect */
place-content: center space-between; /* this handles both axes */
gap: 16px;
}
For Flexbox layouts, place-content is usually more useful than place-items because it controls how flex lines and items distribute within the container.
place-content: center on a flex container to center a group of items as a whole. Use place-items: center on a grid container to center each item within its own cell. The distinction matters when you have multiple items.
Common Alignment Patterns
Hero Section
.hero {
display: grid;
place-items: center;
place-content: center;
min-height: 80vh;
text-align: center;
padding: 40px 20px;
}
Navigation Bar
.navbar {
display: grid;
grid-template-columns: auto 1fr auto;
place-items: center;
padding: 0 24px;
height: 64px;
}
.navbar .logo { place-self: center start; }
.navbar .nav-links { place-self: center; }
.navbar .actions { place-self: center end; }
Footer with Columns
.footer-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
place-items: start;
gap: 40px;
padding: 60px 20px;
}
Alignment Debugging
When alignment doesn't work as expected, check these common issues:
- The container needs an explicit
display: gridordisplay: flex. Place properties do nothing on block elements. - Grid items stretch by default. If your items look full-width when you expected them centered, add
place-items: center. - In Flexbox,
justify-itemsis ignored. Usejustify-contentor switch to Grid. - If
place-contentseems to have no effect, your tracks might already fill the container. There's no extra space to distribute. - The
place-selfproperty on a child overrides the parent'splace-items. Check for conflicting self-alignment.
Browser DevTools make alignment visible. In Chrome, click the grid/flex badge next to an element to see alignment overlays. Firefox's layout panel shows alignment guides for both axes.
Build Better Layouts
CSS alignment works best when combined with other layout tools. Explore these related resources:
- CSS Multi-Column Layout Guide for newspaper-style text columns
- AI CSS Clip-Path Generator for creative shape masking in grid items
- AI Glassmorphism Generator for frosted glass card effects
- AI Box Shadow Generator for depth and elevation in card grids
- AI CSS Transition Generator for smooth hover animations on grid items
The AI CSS Place Items Generator lets you experiment with every alignment combination on a live grid. Toggle between Grid and Flexbox, adjust track sizes, and see exactly how place-items, place-content, and place-self interact. Stop guessing at alignment and start seeing it.