Align-items - Property CSS

align-items

Summary of characteristics of the align-items property

Quick description
Vertical alignment of elements in a flex-box or grid.
Status
Standard
Usable for
HTML
Predefined values
normal | stretch | center | start | end | flex-start | flex-end | self-start | self-end | baseline | first baseline | last baseline
Initial value
normal
Inherited by default
No.
Animation type
Discrète : during an animation, the align-items property passes from one value to another without transition.
W3C Module
CSS Box Alignment Module
References (W3C)
 🡇  
 🡅  
Document status: WD (Working Draft)

Document status: CR (Candidate Recommendation)

Document status: CR (Candidate Recommendation)

Document status: CR (Candidate Recommendation)

Syntactic schema of align-items.

align-items - Syntax DiagramSyntax diagram of the align-items CSS property. normal normal stretch stretch first first last last safe safe unsafe unsafe baseline baseline start start center center end end self-end self-end self-start self-startalign-items:;align-items:;
Syntactic schema of the align-items property
Download the schematic in SVG

Description of the align-items property.

align-items is a CSS property, which manages the placement of elements in a flex container or in a grid cell. This alignment takes into account the direction of filling the flex content, and the direction of writing of the language used. It is important to note that this positioning is done in relation to the line, which is itself positioned in relation to the container with the align-content property.

Application to a flex-box.

The align-items property manages the arrangement of children in a flex box, along the secondary axis. Most of the time (for Latin languages) this will be the vertical axis.
Remember: The secondary axis and the main axis of a flex-box are defined by the flex-direction property.

To manage the layout of each child independently, see the align-self property.

Application to a grid.

The align-items property controls the vertical arrangement of elements relative to their row height. To manage the layout of the rows themselves, see the align-content property.

Values for align-items.

  • align-items: stretch;

    The elements are stretched to fill the full height of the lines.

    Aaaa
    Aaaa
    Aaaa
    Aaaa
    Aaaa
    Aaaa
  • align-items: center;

    The elements are centered in their line.

    Aaaa
    Aaaa
    Aaaa
    Aaaa
    Aaaa
    Aaaa
  • align-items: flex-start; align-items: start;

    These two values are treated in the same way by browsers: the elements are positioned at the beginning of their line. Most of the time (for Latin languages) this will be the top of the line, but it can also be the bottom for other languages. The language taken into account is the one specified for the flex or grid container.

    Aaaa
    Aaaa
    Aaaa
    Aaaa
    Aaaa
    Aaaa
  • align-items: flex-end; align-items: end;

    These two values are equivalent: the elements are positioned at the end of their row. As for start, the notion of end depends on the language of the text, but for Latin languages, it corresponds to the bottom of the line. The language considered is that of the container.

    Aaaa
    Aaaa
    Aaaa
    Aaaa
    Aaaa
    Aaaa
  • align-items: self-start; align-items: self-end;

    Elements are positioned at the beginning or end of their line, both of which are dependent on the language of the element itself (and no longer the language of the container).

    Aaaa
    Aaaa
    Aaaa
    Aaaa
    Aaaa
    Aaaa
  • align-items: baseline; align-items: first baseline; align-items: last baseline;

    The elements are aligned vertically with respect to the baseline of the text.

    If last is specified, the baseline of the last line is used as a reference. We can specify first but it is the value default: First baseline is equivalent to baseline.

    Aaaa
    Aaaa
    Aaaa
    Aaaa
    Aaaa
    Aaaa

    The baseline of a text is located at the base of the letters without jambs.

    Position of the baseline

  • align-items: safe center; align-items: unsafe center;

    The safe and unsafe keywords can be added before the start, end, or center values. They are used to solve the problem of overflow from the top. When an item contains too much content for the available space, that content may be partly masked. If it is centered or aligned from the bottom, the overflow can be done from the top of the element (it is the beginning of the text that is hidden). In this case, even adding a scroll bar will not show the part of the content that is hidden.

    With the word safe, the browser will always place the overflows of content downwards, even if it means not scrupulously respecting the alignment requested. The unsafe value, on the other hand, requires that the alignment be respected, even if this causes an upward overflow.

    This relatively large element extends over several lines and extends beyond the top of the container. The first line of his text is not accessible.
    This second element is smaller and can be displayed in its entirety (no problem).
    align-items:unsafe center;
    This element extends beyond the height of the container. However, it is fully viewable using the scroll bar, including the first few lines.
    This second element is smaller and can be displayed in its entirety (no problem).
    align-items:safe center;

    Since unsafe is the default, it is rarely stated.

Values ​​common to all properties:

align-items: initial (normal) align-items: inherit align-items: revert align-items: revertLayer align-items: unset

Common values ​​are presented on these pages: initial, inherit, revert, revert-layer, unset.

Manipulate the align-items property programmatically.

Change the value of align-items with Javascript.

In Javascript, here's how to change the value of align-items. Javascript supports two syntaxes; one with the typical CSS notation, in kebab-case (a dash to separate words), and another with the camel-case, usual notation in Javascript (a capital letter to separate words).

Javascript
let el = document.getElementById('id'); el.style['align-items'] = 'center'; // or let el = document.getElementById('id'); el.style.alignItems = 'center';

Read the value of align-items in Javascript.

The property must have been assigned directly to the element itself and not through a selector. The value is returned as she has been defines.

Javascript
let el = document.getElementById('id'); let value = el.style['align-items']; // or let el = document.getElementById('id'); let value = el.style.alignItems;

Read the computed value of align-items in Javascript.

The computed value is either the value assigned in the style sheet (or in the style attribute) or the value determined by considering possible legacies and priorities. Otherwise, it will be the initial value of the property (normal in the case of align-items).

In the case of align-items, the value is returned as one of the predefined values accepted by the property.

Javascript
let el = document.getElementById('id'); let value = window.getComputedStyle(el).getPropertyValue('align-items');

Change the value of the align-items property with JQuery.

Two syntaxes (very little different) are also possible in JQuery.

JQuery

$('#id').css('align-items', 'center');
// or
$('#id').css('alignItems', 'center');

Read the computed value of the align-items property with JQuery.

JQuery
let value = $('#id').css('align-items');

Test for yourself.

This small simulator allows you to test for yourself the assignment of the align-items property and the restitution of its value as it was assigned (first button) or its computed value (second button).

Simulator of align-items on a flex-box and on a grid.

Our simulator allows you to see the effect of the align-items property on a flex container and on a grid container. In principle, the flex-start and flex-end values are reserved for flex containers, but we can see that most browsers also process them in the case of a grid.
The font sizes are different between the elements, to illustrate the behavior of the baseline values.


flex-direction : (pour le conteneur flex uniquement)

align-items :

Flex-box
One
Two
(for first)
Three
Grid
One
Two
(for first)
Three
Four
Five
Six

Browser support.

The align-items property is now well recognized by newer browsers, both in the context of a flex-box and in the context of a grid.

Column 1
Support for the align-items property in the context of a flex-box container.
Column 2
Prise en charge de la propriété align-items dans le contexte d'un conteneur grille.

Notes:

(1) In Internet Explorer 10 and 11, if flex elements have align-items:center and their content is too large, they will overflow their container boundaries.

1
align-items
property
(Flex-box)
2
align-items
property
(Grid)
Estimated overall support.
96%
96%

Browsers on computers :

Mobile browsers :

Outdated or marginal browsers :

Internet Explorer

KaiOS Browser

Opéra Mobile

Edge

Opéra

Safari

Safari sur IOS

Androïd Brower

Chrome pour Androïd

Firefox pour Androïd

Samsung Internet

Firefox

Chrome

Baidu Browser

QQ Browser

UC Browser pour Androïd

Opéra mini

align-items property evolution.

The align-items property was first described in the grid or flex-box specifications. But a specific specification to the alignments of the blocks was then created.

  • CSS Flexible Box Layout Module Level 1

    First specification regarding flex-boxes and first description of the align-items property.
    WD
    July 23, 2009
    Working Draft.
    CR
    September 18, 2012
    Candidate Recommendation.
    PR
    REC
  • CSS Grid Layout Module Level 1

    First specification for grids, and introduction of the align-items property.
    WD
    April 07, 2011
    Working Draft.
    CR
    September 29, 2016
    Candidate Recommendation.
    PR
    REC
  • CSS Grid Layout Module Level 2

    No change to the align-items property.
    WD
    February 06, 2018
    Working Draft.
    CR
    August 18, 2020
    Candidate Recommendation.
    PR
    REC
  • CSS Box Alignment Module Level 3

    Creation of a specification module specific to alignments. The description of the align-items property is transferred to this module.
    WD
    June 12, 2012
    Working Draft.
    CR
    PR
    REC

Other properties related to block alignment.

Properties:

align-content
Manages the arrangement of elements in a flex-box or a grid, following the secondary axis.
align-self
Vertical alignment of one of the elements in a flex-box or grid.
column-gap
Langue française
Sets the spacing between columns.
gap
Langue française
Sets spacing between rows and between columns in the context of a grid, flex-box, or multi-column layout)
grid-column-gap
Langue française
Specifies the spacing between columns in a grid.
grid-gap
Langue française
Adjusts the spacing of rows and columns in the context of a grid.
grid-row-gap
Langue française
Specifies the spacing between lines in a grid.
justify-content
Langue française
Defines the positioning along the main axis in a flex-box or grid.
justify-items
Langue française
Manages the horizontal alignment of elements in a grid container.
justify-self
Langue française
Defines the horizontal positioning of a particular element in a flex-box or grid.
place-content
Langue française
Arrange elements in a flex-box or grid.
place-items
Langue française
Defines the placement of elements in their cells (in the context of a grid).
place-self
Langue française
Defines the alignment of an element in both the inline and block directions.
row-gap
Langue française
Defines the space between the lines of a grid.