Open In App

CSS vertical-align Property

Last Updated : 24 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The CSS vertical-align property is used to control the vertical positioning of inline elements or table cells. It helps in aligning images or text within the same line and is commonly used to adjust content in table cells.

This property is perfect for aligning elements relative to each other without affecting the entire layout.

Syntax

vertical-align: baseline | length | sub | super | top | text-top | middle | bottom | text-bottom | initial | inherit;

Note: 

  • The vertical-align property is primarily used to align inline elements (like images) with text.
  • It can also be used for aligning content within table cells.
  • Block-level elements (e.g., div, p, h1, ul, ol) cannot be aligned using vertical-align.

Property Values

ValueDescription
baselineAligns the element’s baseline with the baseline of its parent.
This is the default value and may vary by browser.
subPositions the element’s baseline as a subscript relative to its parent’s baseline.
superPositions the element’s baseline as a superscript relative to its parent’s baseline.
text-topAligns the top of the element with the top of the parent’s font.
text-bottomAligns the bottom of the element with the bottom of the parent’s font.
middleCenters the element’s vertical midpoint with the parent’s vertical midpoint.
topAligns the element’s top with the top of the tallest element in the same line.
bottomAligns the element’s bottom with the bottom of the shortest element in the same line.
lengthMoves the element’s baseline by a specified length above (or below for negative values) the parent’s baseline.
percentageShifts the element’s baseline by a percentage relative to the parent’s baseline, based on the line-height property.
initialResets the alignment to the default value (baseline).
inheritAdopts the vertical alignment value from the parent element.

Let’s understand this property through this example

Example: This example explains all the values of vertical-align property. 

HTML
<!DOCTYPE html>
<html>
    
<head>
    <title>
        CSS vertical-align Property
    </title>
    
    <style>
        .img1 {
            vertical-align: baseline;
        }
        .img2 {
            vertical-align: sub;
        }
        .img3 {
            vertical-align: super;
        }
        .img4 {
            vertical-align: text-top;
        }
        .img5 {
            vertical-align: text-bottom;
        }
        .img6 {
            vertical-align: middle;
        }
        .img7 {
            vertical-align: top;
        }
        .img8 {
            vertical-align: bottom;
        }
        .img9 {
            vertical-align: 25px;
        }
        img.img10 {
            vertical-align: 100%;
        }
        .img11 {
            vertical-align: baseline;
        }
        .img12 {
            vertical-align: inherit;
        }
    </style>
</head>

<body>
    <h2>vertical-align: baseline</h2>
    <p>
        <img class = "img1" src =
"https://media.geeksforgeeks.org/wp-content/uploads/gfgc.png" 
        alt = "" class="alignnone size-medium wp-image-862984" />
        A computer science portal
    </p><br>
    
    
    <h2>vertical-align: sub</h2> 
    <p>
        <img class = "img2" src =
"https://media.geeksforgeeks.org/wp-content/uploads/gfgc.png" 
        alt = "" class="alignnone size-medium wp-image-862984" />
        A computer science portal
    </p><br>
    
    
    <h2>vertical-align: super</h2>
    <p>
        <img class = "img3" src =
"https://media.geeksforgeeks.org/wp-content/uploads/gfgc.png" 
        alt = "" class="alignnone size-medium wp-image-862984" />
        A computer science portal
    </p><br>
    
    
    <h2>vertical-align: text-top</h2>
    <p>
        <img class = "img4" src =
"https://media.geeksforgeeks.org/wp-content/uploads/gfgc.png" 
        alt = "" class="alignnone size-medium wp-image-862984" />
        A computer science portal
    </p><br>
    
    
    <h2>vertical-align: text-bottom</h2> 
    <p>
        <img class = "img5" src =
"https://media.geeksforgeeks.org/wp-content/uploads/gfgc.png" 
        alt = "" class="alignnone size-medium wp-image-862984" />
        A computer science portal
    </p><br>
    
    
    <h2>vertical-align: middle</h2>
    <p>
        <img class = "img6" src =
"https://media.geeksforgeeks.org/wp-content/uploads/gfgc.png" 
        alt = "" class="alignnone size-medium wp-image-862984" />
        A computer science portal
    </p><br>
    
    
    <h2>vertical-align: top</h2>
    <p>
        <img class = "img7" src =
"https://media.geeksforgeeks.org/wp-content/uploads/gfgc.png" 
        alt = "" class="alignnone size-medium wp-image-862984" />
        A computer science portal
    </p><br>
    
    
    <h2>vertical-align: bottom</h2>
    <p>
        <img class = "img8" src =
"https://media.geeksforgeeks.org/wp-content/uploads/gfgc.png" 
        alt = "" class="alignnone size-medium wp-image-862984" />
        A computer science portal
    </p><br>
    
    
    <h2>vertical-align: length</h2>
    <p>
        <img class = "img9" src =
"https://media.geeksforgeeks.org/wp-content/uploads/gfgc.png" 
        alt = "" class="alignnone size-medium wp-image-862984" />
        A computer science portal
    </p><br>
    
    
    <h2>vertical-align: percentage</h2>
    <p>
        <img class = "img10" src =
"https://media.geeksforgeeks.org/wp-content/uploads/gfgc.png" 
        alt = "" class="alignnone size-medium wp-image-862984" />
        A computer science portal
    </p><br>
    
    
    <h2>vertical-align: initial</h2>
    <p>
        <img class = "img11" src =
"https://media.geeksforgeeks.org/wp-content/uploads/gfgc.png" 
        alt = "" class="alignnone size-medium wp-image-862984" />
        A computer science portal
    </p><br>
    
    
    <h2>vertical-align: inherit</h2>
    <p>
        <img class = "img12" src =
"https://media.geeksforgeeks.org/wp-content/uploads/gfgc.png" 
        alt = "" class="alignnone size-medium wp-image-862984" />
        A computer science portal
    </p>
    </body>
</html>                    

Output:

Supported Browsers

The browser supported by vertical-align property are listed below:

  • Chrome 1.0
  • Edge 12.0
  • Firefox 1.0
  • Internet Explorer 4
  • Safari 1.0
  • Opera 4.0


Next Article

Similar Reads