CSS Vertical Align

The CSS vertical-align property is used to align inline-level elements vertically within a line box. It is commonly used for aligning text or inline elements like images and form elements. This property can be applied to inline, inline-block, or table-cell elements.

Key Points on CSS Vertical Align:

Syntax for CSS Vertical Align:

Syntax Example

/* Vertical Align Syntax */
            vertical-align: value;
        
            /* Example */
            vertical-align: middle;

Examples of CSS Vertical Align:

The following examples demonstrate how to use the vertical-align property in different scenarios:

Code Example: Aligning Text


            span {
            vertical-align: middle;
                 }

Output

This text is vertically aligned in the middle.

Code Example: Aligning Inline Images


            img {
            vertical-align: middle;
                }

Output

Inline Image This image is vertically aligned with the text.

Code Example: Aligning Inline-block Elements


            div {
            display: inline-block;
            vertical-align: top;
            height: 50px;
            width: 50px;
            background-color: lightblue;
                 }

Output

Common Values for Vertical Align:

When using vertical-align with inline elements, make sure the parent element has enough space to accommodate the alignment. For block-level elements, consider using display: inline-block or table-cell to apply vertical alignment.