Flex Item Alignment Override with align-self
Override the container's align-items for individual flex items using align-self.
Flex Item Alignment Override with align-self is a free CSS Academy lesson on CoddyKit. This is lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the CSS Academy learning path, and your progress syncs across the web and the CoddyKit app. The CSS Academy course includes 4 lessons in total.
What is align-self?
align-self overrides the flex container's align-items setting for a specific flex item. It applies to individual items, not the container.
align-self Values
Accepts the same values as align-items:
auto— inherits container's align-items (default)flex-start— aligns to cross startflex-end— aligns to cross endcenter— centers on cross axisstretch— stretches to fill cross sizebaseline— aligns text baselines
Practical Example
A navigation where most items are centered but the last button is aligned to the end:
<nav class="nav">
<span>Logo</span>
<a href="#">Link</a>
<button class="cta-button">Sign Up</button>
</nav>
Stretching One Item
Make one card stretch to full height while others shrink-wrap:
<div class="sidebar-layout">
<div>Content</div>
<div class="ad-unit">Ad</div>
</div>
margin: auto as Alignment
Auto margins on flex items push themselves (or siblings) to the opposite side. This is a powerful alternative to align-self for centering or distributing space.
<nav class="nav">
<span class="logo">Logo</span>
<a href="#">Home</a>
<a href="#">About</a>
<span class="settings">⚙</span>
</nav>
margin: auto Vertical Centering
Auto margins work vertically too. margin-top: auto inside a column flex container pushes an element to the bottom:
<div class="card">
<p>Card body</p>
<div class="card-footer">Footer</div>
</div>
Baseline Alignment
Aligning items by text baseline keeps readable relationships between items of different sizes:
<div class="stats-row">
<span class="big-number">42</span>
<span class="label">users</span>
</div>
align-self: auto (Default)
align-self: auto tells the item to use the container's align-items value. You only need to set align-self when you want to deviate from the container's default.
Cross Axis vs Main Axis
Remember: align-self always operates on the cross axis. If flex-direction: column, the cross axis is horizontal, so align-self controls left/right positioning.
Combining align-self with flex-grow
A common pattern: grow an item to fill space AND override its cross alignment:
<div class="features">
<div class="feature-card">Feature A</div>
<div>Feature B</div>
</div>
Grid vs Flexbox Alignment
CSS Grid has both align-self (row axis) and justify-self (column axis) for 2D control. Flexbox's align-self only controls the cross axis — use margin: auto for the main axis.
Quick Check
A flex container has align-items: center. One item needs to align to the top of the cross axis. What property should you set on that item?
Recap
align-self overrides the flex container's align-items for individual items. Use it to break the alignment pattern for specific elements. margin: auto is a complementary tool that distributes remaining space to push items along either axis.
Learn CSS with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 40
- Lessons
- 159
Frequently Asked Questions
Is the “Flex Item Alignment Override with align-self” lesson free?
Yes — the full text of “Flex Item Alignment Override with align-self” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the CSS Academy course, upgrade to CoddyKit PRO. The CSS Academy course includes 4 lessons in total.
What will I learn in “Flex Item Alignment Override with align-self”?
Override the container's align-items for individual flex items using align-self. You practise CSS Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start CSS Academy?
No prior experience is required. CSS Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 4.
How long does the “Flex Item Alignment Override with align-self” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this CSS Academy lesson?
Yes. Every CSS Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Flex Item Alignment Override with align-self
- Order Property and Visual Reordering
- Flex Shorthand Patterns
- Common Flexbox Layouts: Nav Cards Media Object