HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
  • Insights
  • Verify Certificate
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials

HTML5andCSS3.org helps developers learn modern frontend skills with practical tutorials, production-ready snippets, and fast web tools built for everyday coding.

Quick Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Copyright
  • Disclaimer

Top Tools

  • Try It Editor
  • JSON Formatter
  • CSS Minifier
  • HTML Minifier
  • Base64 Encoder / Decoder

Contact

  • business@html5andcss3.org
Newsletter

Learn at your own pace, practice with useful tools, and build websites you're proud of.

© 2011-2026 html5andcss3.org. All rights reserved.

How to Use

CSS Tutorial

CSS Introduction

What is CSSCSS SyntaxHow to Add CSSCSS Comments

CSS Foundations

Cascade & InheritanceCSS SpecificityCSS UnitsBox SizingCSS VariablesCSS Math Functions

CSS Selectors

CSS Element SelectorCSS Class SelectorCSS ID SelectorCSS Universal SelectorCSS Group SelectorCSS CombinatorsCSS Attribute SelectorsCSS Pseudo ClassesCSS Pseudo Elements

CSS Colors and Backgrounds

CSS ColorsCSS HEX ColorsCSS RGB ColorsModern ColorsCSS Background ColorCSS Background ImageLayered Backgrounds

CSS Text & Fonts

CSS Text ColorCSS Text AlignmentCSS Text DecorationCSS Font FamilyCSS Font SizeWeb Fonts & TypographyText Wrapping

CSS Box Model

CSS MarginCSS PaddingCSS BorderCSS OutlineCSS Width and Height

CSS Layout

Normal FlowCSS DisplayCSS PositionAnchor PositioningCSS FloatCSS OverflowCSS Z-indexIntrinsic SizingAspect Ratio & Object FitMulti-column Layout

CSS Flexbox

Flex ContainerFlex DirectionJustify ContentAlign ItemsFlex WrapFlex Item Sizing

CSS Grid

CSS Grid ContainerCSS Grid ColumnsCSS Grid RowsCSS Grid GapCSS Grid Layout ExampleGrid PlacementGrid AreasCSS Subgrid

CSS Lists, Tables & Forms

CSS ListsCSS TablesCSS Form StylingCSS Input Fields

CSS Effects

CSS ShadowsCSS GradientsCSS FiltersCSS OpacityClipping & MaskingBlending & BackdropScroll Snap

CSS Animations & Transitions

CSS TransformCSS 2D TransformCSS 3D TransformCSS TransitionsEntry & Exit TransitionsCSS AnimationsScroll AnimationsView TransitionsMotion Paths

CSS Responsive Design

CSS Media QueriesResponsive LayoutMobile First DesignContainer QueriesPreference Media QueriesFeature Queries

Modern CSS Authoring

Cascade LayersNesting & ScopeLogical PropertiesGenerated Content

CSS Accessibility

Accessible CSSCSS ThemingModern Form StylingCSS User Interface

CSS Output & Performance

Print StylesCSS PerformanceCSS ArchitectureDebugging CSS

CSS Reference

CSS At-rulesCSS FunctionsCSS Tutorial PDF

CSS Projects

Responsive CSS Project
  1. Home
  2. /
  3. Tutorials
  4. /
  5. CSS Tutorial
  6. /
  7. Align Items

CSS Flexbox

Align Items

The align-items property is used to control the alignment of flex items along the cross axis of a flex container.

While justify-content controls alignment on the main axis, align-items controls alignment on the cross axis. The supporting concepts are explained in Justify Content and Flex Item Sizing.

For a flex container with:

css

flex-direction: row;

Main Axis -> Horizontal
Cross Axis -> Vertical

The align-items property is commonly used to center items vertically, align them at the top or bottom, or stretch them to fill available space.

Syntax

Align Items Syntax

css

.container {
    display: flex;
    align-items: value;
}

Align Items Example

css

.container {
    display: flex;
    align-items: center;
}

This vertically centers all flex items inside the flex container.

Attributes

ValueDescriptionExample
stretchDefault. Stretches items to fill containeralign-items: stretch;
flex-startAligns items at the start of cross axisalign-items: flex-start;
centerCenters items on cross axisalign-items: center;
flex-endAligns items at the end of cross axisalign-items: flex-end;
baselineAligns items based on text baselinealign-items: baseline;

Example

Align Items Complete Example

html

<!DOCTYPE html>
<html>
<head>
    <title>Align Items Example</title>
    <style>
        .container {
            display: flex;
            align-items: center;
            height: 200px;
            border: 2px solid black;
            gap: 10px;
        }
        .item {
            background-color: lightblue;
            padding: 20px;
            border: 1px solid #333;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="item">Item 1</div>
        <div class="item">Item 2</div>
        <div class="item">Item 3</div>
    </div>
</body>
</html>

Browser Support

Feature
Chrome
Edge
Firefox
Safari
align-items in Flexbox5212207

Versions show the first stable desktop release with unprefixed support. Data source: MDN Browser Compatibility Data 8.0.8.

Notes

  • align-items works along the cross axis.
  • For flex-direction: row, it controls vertical alignment.
  • For flex-direction: column, it controls horizontal alignment.
  • It only affects flex items inside a flex container.
  • Frequently combined with justify-content for perfect centering.

Perfect Centering Example

Perfect Centering Example

css

.container {
    display: flex;
    justify-content: center;
    align-items: center;
}

Centers content both horizontally and vertically.

Visual Comparison

flex-start

text

Item1 Item2 Item3
-----------------

center

text

-----------------
Item1 Item2 Item3
-----------------

flex-end

text

-----------------
                 Item1 Item2 Item3

stretch

text

[Item1][Item2][Item3]

Conclusion

The align-items property controls how flex items are aligned along the cross axis. Whether you need top alignment, bottom alignment, stretching, or perfect vertical centering, align-items provides a simple and powerful solution for modern Flexbox layouts.

PreviousJustify ContentNextFlex Wrap