July 5th, 2024

Vertical-Align: All You Need to Know (CSS)

This article explains the CSS property vertical-align, detailing its role in aligning text and elements. It covers aligning baselines, tops, bottoms, centering icons, and addressing gaps in 30 words.

Read original articleLink Icon
Vertical-Align: All You Need to Know (CSS)

This article delves into the CSS property vertical-align, explaining its role in aligning text and elements next to each other. It clarifies the behavior of vertical-align by discussing how it works with inline-level elements in line boxes, aligning baselines, tops, and bottoms. The piece provides examples on centering icons, moving baselines, and addressing gaps below inline-level elements. It emphasizes the importance of understanding line boxes, inline elements, and how vertical-align affects their alignment. The text also covers aligning elements relative to the line box's baseline, text box, and outer edges. By exploring various scenarios and pitfalls related to vertical-align, the article aims to provide a comprehensive understanding of this CSS property.

Link Icon 2 comments
By @padolsey - 10 months
This article is ten years old; thought that worth flagging. Nowadays I find myself more comfortable using flexbox and grids to manage these kinds of layout subtleties. Or when in complete dismay, using the `top:50%;left:50%;translate(-50%,-50%)` hack. I find inline elements less reliable and less 'knowable', especially in responsive layouts. I think I only end up using vertical-align in incredibly narrow use-cases. Though curious to hear other peoples' experiences.