Home CSS Properties vertical-align CSS vertical-align Property Definition
Definition and Usage The vertical-align property sets the vertical alignment of an inline , inline-block , or table-cell box. Use it to sit an icon next to text, or to place content inside a table cell.
It does not align ordinary block boxes (such as a plain div). For flex or grid, prefer align-items . The initial value is baseline. It is not inherited.
Baseline · Widely available. Not deprecated. Supported everywhere modern browsers run. Do not use it to vertically center a block page section — use flex or grid instead.
Syntax
CSS Syntax vertical-align: baseline | middle | top | bottom | <length> | <percentage> ;
Also: sub, super, text-top, text-bottom. Example: vertical-align: middle;
Values
Property Values Value Description Try it baselineAlign baselines (initial value) Try itmiddleAlign middle with parent baseline + half x-height Try ittop / bottomAlign to the top or bottom of the line (or table row) Try itsub / superSubscript or superscript baseline Try itLength / % Raise or lower from the baseline (% of line-height ) Try it
Approach
How to Use vertical-align Apply it to an inline-level or table-cell element, then pick a keyword that matches the look you want.
Confirm the element is inline, inline-block, or a table cell (display ). Set vertical-align on that element (not on a wrapping block alone). For icons beside text, start with middle. For table cells, use top, middle, or bottom on the cell. Piece Required? Role Inline / table-cell box Yes Block boxes ignore this property Keyword or offset Yes baseline, middle, top, length, etc.Line of text or table row Usually Gives something to align against
Try it
Live Preview The blue box is inline-block. Change vertical-align and watch it move relative to the text.
Code
CSS Examples Each snippet focuses on vertical-align. Extra styles stay minimal for study. Use Try It Yourself for a live editor.
1. Middle 2. Baseline 3. Table cell Example 1 — Align an Inline Box with Text Sit a small box on the middle of the text line.
<style>
span {
display: inline-block;
width: 24px;
height: 24px;
background: #2563eb;
vertical-align: middle;
}
</style>
<p>Label <span></span> text</p> How It Works Make it inline-level. display: inline-block lets vertical-align apply.Set middle. The box centers against the parent text metrics.Keep it in the line. The span sits inside the paragraph with the words.Common pattern. Same idea for icons and small images beside labels.Example 2 — Default Baseline Compare the default baseline alignment with taller inline content.
<style>
span {
display: inline-block;
width: 24px;
height: 40px;
background: #2563eb;
vertical-align: baseline;
}
</style>
<p>Label <span></span> text</p> How It Works Baseline is the default. The box lines up on the text baseline.Tall boxes stick up. Extra height grows above the baseline.Try middle next. Switch to middle in Try It Yourself for a cleaner icon look.Images vary. Some replaced elements treat baseline differently across browsers.Example 3 — Table Cell Alignment Center content vertically inside a table cell.
<style>
td {
height: 80px;
vertical-align: middle;
border: 1px solid #ccc;
}
</style>
<table>
<tr>
<td>Centered</td>
</tr>
</table> How It Works Cells accept it. td / th are table-cell boxes.Give the cell height. Extra vertical space makes middle visible.middle centers. Content sits in the vertical middle of the row.Also try top/bottom. Those pin content to the row edges. Edge Cases & Pitfalls If nothing moves, one of these is usually why.
block Ignored on block boxes A normal div will not respond. Use inline-block/table-cell, or flex/grid align-items .
flex Not for flex/grid centering Vertical centering of flex items is align-items / align-self , not vertical-align.
% Percentages use line-height A percentage is relative to the element’s line-height , not the parent height.
img Images and baseline Default image alignment is often baseline, which can leave a gap under the image. Try middle or bottom.
inherit Not inherited Children do not pick up a parent’s vertical-align unless you set inherit.
Compatibility
Browser Support vertical-align is a browser CSS property for inline and table-cell layout. Node.js, Deno, and Bun do not apply it.
✓ Baseline · Widely available
vertical-align Supported in all major browsers for many years (Chrome 1+, Firefox 1+, Safari 1+, Edge 12+, IE 4+).
Google Chrome 1+
Full support
Mozilla Firefox 1+
Full support
Apple Safari 1+
Full support
Microsoft Edge 12+
Full support
Opera 4+
Full support
Samsung Internet 1+
Full support
Internet Explorer 4+
Full support vertical-align Widely supported
Bottom line: Safe everywhere for inline and table-cell use. Remember it is not a flex/grid centering tool. This is not a JavaScript runtime API.
Remember
Key Takeaways Role: align inline / inline-block / table-cell boxes vertically.
Initial: baseline. middle is the usual pick for icons beside text.
Not for blocks. Use flex/grid align-items to center block layout.
Table cells: top, middle, and bottom align within the row.
One line: vertical-align is for inline and table-cell alignment — not for centering block pages.
Frequently Asked Questions What does the CSS vertical-align property do? It sets the vertical alignment of an inline, inline-block, or table-cell box. For inline content it aligns inside the line box. For table cells it aligns the cell’s content within the row.
What is the default value of vertical-align? The initial value is baseline, which lines up the element’s baseline with the parent’s baseline.
Why does vertical-align not work on a div? It does not apply to block-level boxes. Change display to inline-block or table-cell, or use flex/grid with align-items for block layout.
Is vertical-align inherited? No. Set it on each inline or table-cell element that needs a different alignment.
When should I use middle? middle is a common choice to sit an icon or image beside text so their middles line up with the parent’s x-height.
Which browsers support vertical-align? It is Baseline Widely available and supported in all major browsers, including Internet Explorer. It is a browser CSS property, not a Node.js feature.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful
Helpful Share Copy link Suggestion