files/en-us/web/css/reference/properties/vertical-align/index.md
The vertical-align CSS property sets vertical alignment of an inline, inline-block or table-cell box.
{{InteractiveExample("CSS Demo: vertical-align")}}
vertical-align: baseline;
vertical-align: top;
vertical-align: middle;
vertical-align: bottom;
vertical-align: sub;
vertical-align: text-top;
<section class="default-example" id="default-example">
<p>
Align the star:
</p>
</section>
#default-example > p {
line-height: 3em;
font-family: monospace;
font-size: 1.2em;
text-decoration: underline overline;
}
The vertical-align property can be used in two contexts:
Note that vertical-align only applies to inline, inline-block and table-cell elements: you can't use it to vertically align block-level elements.
/* Keyword values */
vertical-align: baseline;
vertical-align: sub;
vertical-align: super;
vertical-align: text-top;
vertical-align: text-bottom;
vertical-align: middle;
vertical-align: top;
vertical-align: bottom;
/* <length> values */
vertical-align: 10em;
vertical-align: 4px;
/* <percentage> values */
vertical-align: 20%;
/* Global values */
vertical-align: inherit;
vertical-align: initial;
vertical-align: revert;
vertical-align: revert-layer;
vertical-align: unset;
The vertical-align property is specified as one of the values listed below.
These values vertically align the element relative to its parent element:
baseline
sub
super
text-top
text-bottom
middle
The following values vertically align the element relative to the entire line:
top
bottom
For elements that do not have a baseline, the bottom margin edge is used instead.
baseline (and sub, super, text-top, text-bottom, <length>, and <percentage>)
top
middle
bottom
Negative values are allowed.
{{CSSInfo}}
{{csssyntax}}
<div>
An image with
a default alignment.
</div>
<div>
An
image with a text-top alignment.
</div>
<div>
An
image with a text-bottom alignment.
</div>
<div>
An
image with a middle alignment.
</div>
img.top {
vertical-align: text-top;
}
img.bottom {
vertical-align: text-bottom;
}
img.middle {
vertical-align: middle;
}
{{EmbedLiveSample("Basic_example")}}
<p>
top:
middle:
bottom:
super:
sub:
</p>
<p>
text-top:
text-bottom:
0.2em:
-1em:
20%:
-100%:
</p>
#* {
box-sizing: border-box;
}
img {
margin-right: 0.5em;
}
p {
height: 3em;
padding: 0 0.5em;
font-family: monospace;
text-decoration: underline overline;
margin-left: auto;
margin-right: auto;
width: 80%;
}
{{EmbedLiveSample("Vertical_alignment_in_a_line_box", '100%', 160, "", "")}}
In this example, we have a table with a single row containing six cells. The row sets vertical-align to bottom as the default value.
vertical-align values, and these override the row's value.vertical-align value, so inherits the row's value.The sixth cell is only used to ensure that the cells are tall enough to see the effect.
<table>
<tbody>
<tr class="bottom">
<td class="baseline">baseline</td>
<td class="top">top</td>
<td class="middle">middle</td>
<td>bottom</td>
<td>Row's style</td>
<td>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse
pretium felis eu sem mattis vulputate.
</td>
</tr>
</tbody>
</table>
table {
margin-left: auto;
margin-right: auto;
width: 80%;
}
table,
th,
td {
border: 1px solid black;
}
td {
padding: 0.5em;
font-family: monospace;
}
.bottom {
vertical-align: bottom;
}
.baseline {
vertical-align: baseline;
}
.top {
vertical-align: top;
}
.middle {
vertical-align: middle;
}
{{EmbedLiveSample("Vertical_alignment_in_a_table_cell", '100%', 230, "", "")}}
{{Specifications}}
{{Compat}}
vertical-align, or "How (Not) To Vertically Center Content"