vertical-align

  • Revision slug: CSS/vertical-align
  • Revision title: vertical-align
  • Revision id: 298735
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment

Revision Content

{{ CSSRef() }}

Summary

The vertical-align CSS property specifies the vertical alignment of an inline or table-cell element.

  • {{ Xref_cssinitial() }}: baseline
  • Applies to: inline elements and table cells
  • {{ Xref_cssinherited() }}: No
  • Media: {{ Xref_cssvisual() }}
  • {{ Xref_csscomputed() }}:

Syntax

vertical-align: baseline | sub | super | text-top | text-bottom | middle | top | bottom | <percentage> | <length>

Values (for inline elements)

Most of the values vertically align the element relative to its parent element:

baseline
Align the baseline of the element with the baseline of its parent.
sub
Align the baseline of the element with the subscript-baseline of its parent.
super
Align the baseline of the element with the superscript-baseline of its parent.
text-top
Align the top of the element with the top of the parent element's font.
text-bottom
Align the bottom of the element with the bottom of the parent element's font.
middle
Align the middle of the element with the middle of lowercase letters in the parent.
<length>
Align the baseline of the element at the given length above the baseline of its parent.
<percentage>
like <length> values, with the percentage being a percent of the {{ Cssxref("line-height") }} property.

For elements that do not have a baseline, the bottom margin edge is used instead.

However, two values vertically align the element relative to the entire line rather than relative to its parent:

top
Align the top of the element and its descendants with the top of the entire line.
bottom
Align the bottom of the element and its descendants with the bottom of the entire line.

Negative values are allowed.

Values (for table cells)

baseline (and sub, super, text-top, text-bottom, <length>, and <percentage>)
Align the baseline of the cell with the baseline of all other cells in the row that are baseline-aligned.
top
Align the top padding edge of the cell with the top of the row.
middle
Center the padding box of the cell within the row.
bottom
Align the bottom padding edge of the cell with the bottom of the row.

Negative values are allowed.

Examples

img {
	vertical-align: bottom;
}

Specifications

Specification Status Comment
{{ SpecName('CSS3 Transitions', '#animatable-css', 'vertical-align') }} {{ Spec2('CSS3 Transitions') }} Defines visibility as animatable.
{{ SpecName('CSS2.1', 'visudet.html#propdef-vertical-align', 'vertical-align') }} {{ Spec2('CSS2.1') }} Add the {{ xref_csslength() }} value and allows it to be applied to element with a {{ cssxref("display") }} type of table-cell.
{{ SpecName('CSS1', '#vertical-align', 'vertical-align') }} {{ Spec2('CSS1') }} Initial definition.

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 {{ CompatGeckoDesktop("1.0") }} 4.0 4.0 1.0 (85)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 1.0 1.0 {{ CompatGeckoMobile("1.0") }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} 1.0

See also

Revision Source

<p>{{ CSSRef() }}</p>
<h2 id="Summary" name="Summary">Summary</h2>
<p>The <code>vertical-align</code> <a href="/en/CSS" title="CSS">CSS</a> property specifies the vertical alignment of an inline or table-cell element.</p>
<ul class="cssprop">
  <li><dfn>{{ Xref_cssinitial() }}:</dfn> <code>baseline</code></li>
  <li><dfn>Applies to:</dfn> inline elements and table cells</li>
  <li><dfn>{{ Xref_cssinherited() }}:</dfn> No</li>
  <li><dfn>Media:</dfn> {{ Xref_cssvisual() }}</li>
  <li><dfn>{{ Xref_csscomputed() }}:</dfn></li>
</ul>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre>
<code>vertical-align:</code> <code>baseline</code> | <code>sub</code> | <code>super</code> | <code>text-top</code> | <code>text-bottom</code> | <code>middle</code> | <code>top</code> | <code>bottom</code> | &lt;percentage&gt; | <a href="/en/CSS/length" title="en/CSS/length">&lt;length&gt;</a></pre>
<h3 id="Values_(for_inline_elements)">Values (for inline elements)</h3>
<p>Most of the values vertically align the element relative to its parent element:</p>
<dl>
  <dt>
    <code>baseline</code></dt>
  <dd>
    Align the baseline of the element with the baseline of its parent.</dd>
  <dt>
    <code>sub</code></dt>
  <dd>
    Align the baseline of the element with the subscript-baseline of its parent.</dd>
  <dt>
    <code>super</code></dt>
  <dd>
    Align the baseline of the element with the superscript-baseline of its parent.</dd>
  <dt>
    <code>text-top</code></dt>
  <dd>
    Align the top of the element with the top of the parent element's font.</dd>
  <dt>
    <code>text-bottom</code></dt>
  <dd>
    Align the bottom of the element with the bottom of the parent element's font.</dd>
  <dt>
    <code>middle</code></dt>
  <dd>
    Align the middle of the element with the middle of lowercase letters in the parent.</dd>
  <dt>
    <code><a href="/en/CSS/length" title="en/CSS/length">&lt;length&gt;</a></code></dt>
  <dd>
    Align the baseline of the element at the given length above the baseline of its parent.</dd>
  <dt>
    <code>&lt;percentage&gt;</code></dt>
  <dd>
    like &lt;length&gt; values, with the percentage being a percent of the {{ Cssxref("line-height") }} property.
    <p>For elements that do not have a baseline, the bottom margin edge is used instead.</p>
    <p>However, two values vertically align the element relative to the entire line rather than relative to its parent:</p>
  </dd>
  <dt>
    <code>top</code></dt>
  <dd>
    Align the top of the element and its descendants with the top of the entire line.</dd>
  <dt>
    <code>bottom</code></dt>
  <dd>
    Align the bottom of the element and its descendants with the bottom of the entire line.</dd>
</dl>
<p>Negative values are allowed.</p>
<h3 id="Values_(for_table_cells)">Values (for table cells)</h3>
<dl>
  <dt>
    <code>baseline</code> (and <code>sub</code>, <code>super</code>, <code>text-top</code>, <code>text-bottom</code>, <code>&lt;length&gt;</code>, and <code>&lt;percentage&gt;</code>)</dt>
  <dd>
    Align the baseline of the cell with the baseline of all other cells in the row that are baseline-aligned.</dd>
  <dt>
    <code>top</code></dt>
  <dd>
    Align the top padding edge of the cell with the top of the row.</dd>
  <dt>
    <code>middle</code></dt>
  <dd>
    Center the padding box of the cell within the row.</dd>
  <dt>
    <code>bottom</code></dt>
  <dd>
    Align the bottom padding edge of the cell with the bottom of the row.</dd>
</dl>
<p>Negative values are allowed.</p>
<h2 id="Examples" name="Examples">Examples</h2>
<pre class="brush: css">
img {
	vertical-align: bottom;
}
</pre>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
  <thead>
    <tr>
      <th scope="col">Specification</th>
      <th scope="col">Status</th>
      <th scope="col">Comment</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>{{ SpecName('CSS3 Transitions', '#animatable-css', 'vertical-align') }}</td>
      <td>{{ Spec2('CSS3 Transitions') }}</td>
      <td>Defines <code>visibility</code> as animatable.</td>
    </tr>
    <tr>
      <td>{{ SpecName('CSS2.1', 'visudet.html#propdef-vertical-align', 'vertical-align') }}</td>
      <td>{{ Spec2('CSS2.1') }}</td>
      <td>Add the {{ xref_csslength() }} value and allows it to be applied to element with a {{ cssxref("display") }} type of <code>table-cell</code>.</td>
    </tr>
    <tr>
      <td>{{ SpecName('CSS1', '#vertical-align', 'vertical-align') }}</td>
      <td>{{ Spec2('CSS1') }}</td>
      <td>Initial definition.</td>
    </tr>
  </tbody>
</table>
<h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>1.0</td>
        <td>{{ CompatGeckoDesktop("1.0") }}</td>
        <td>4.0</td>
        <td>4.0</td>
        <td>1.0 (85)</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Android</th>
        <th>Chrome for Android</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>IE Mobile</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>1.0</td>
        <td>1.0</td>
        <td>{{ CompatGeckoMobile("1.0") }}</td>
        <td>{{ CompatVersionUnknown() }}</td>
        <td>{{ CompatVersionUnknown() }}</td>
        <td>1.0</td>
      </tr>
    </tbody>
  </table>
</div>
<h2 id="See_also" name="See_also">See also</h2>
<ul>
  <li>{{ Cssxref("line-height") }}, {{ Cssxref("text-align") }}, {{ Cssxref("margin") }}</li>
  <li>
    <p><a href="http://phrogz.net/css/vertical-align/index.html" title="http://phrogz.net/css/vertical-align/index.html">Understanding <code>vertical-align</code>, or "How (Not) To Vertically Center Content"</a></p>
  </li>
</ul>
Revert to this revision