align-items: baseline Alignment for Typography
You'll learn how to use align-items: baseline to perfectly align text across flex items, even when they have different font sizes or padding.
What Is Baseline Alignment?
Imagine a classroom where students of different heights are sitting at desks. If you want their eyes all at the same level, you'd adjust their chair heights differently. That's what baseline does for text in flexbox.
In typography, the baseline is the invisible line that letters "sit" on—the bottom of most lowercase letters (excluding descenders like in g or p). When you set align-items: baseline on a flex container, all flex items align so their text baselines match, regardless of font size, padding, or container height.
Why Use Baseline Alignment?
Without baseline alignment, flex items with different font sizes or padding often look misaligned. A large heading next to small body text might float at different visual levels. Baseline alignment solves this by treating the text itself—not the box edges—as the alignment reference.
.container {
display: flex;
align-items: baseline; /* Align text baselines */
}
.large-text {
font-size: 32px;
padding: 10px;
}
.small-text {
font-size: 16px;
padding: 5px;
}
Even though .large-text and .small-text have different sizes and padding, their text will sit on the same baseline, creating visual harmony.
When to Use It
This is perfect for navigation menus, mixed-size labels, or any layout where text from different elements should appear "on the same line" visually—like prices next to product names or icons next to labels.
Key Takeaway: Use align-items: baseline to align the text baselines of flex items, ensuring typographic consistency across elements with different sizes or spacing.