Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Cross Axis Alignment | Aligning and Distributing Elements
CSS Flexbox Foundations

bookCross Axis Alignment

When you want to control how items are aligned along the cross axis in a flex container, you use the align-items property. This property determines how the flex items are positioned vertically (if your flex direction is row) or horizontally (if your flex direction is column) within the container. The most common values for align-items are:

  • flex-start: aligns items to the start of the cross axis;
  • flex-end: aligns items to the end of the cross axis;
  • center: centers items along the cross axis;
  • stretch: stretches items to fill the container (the default);
  • baseline: aligns items so their text baselines line up.

For containers that wrap onto multiple lines, the align-content property lets you control the spacing and alignment of the entire lines of items along the cross axis, rather than just individual items.

index.html

index.html

copy

In the example above, you see a flex container with three items. The container uses align-items: flex-end, which means all the items are aligned to the bottom of the container—the end of the cross axis. No matter what their heights are, the items' bottoms line up with the container's bottom edge. If you changed align-items to center, the items would be centered vertically within the container; with stretch, they would expand to fill the container’s height.

index.html

index.html

copy

It is important to understand the difference between align-items and align-content. The first example demonstrates align-items, which aligns all the flex items within a single line of the flex container. This affects the vertical placement of each item relative to the container's cross axis.

In contrast, the second example uses align-content with wrapping enabled. Here, the container has enough items to create more than one line. The align-content: space-around property distributes the lines of items evenly along the cross axis, adding space above, between, and below the rows of items. While align-items aligns items within each line, align-content manages the spacing between the lines themselves when there is extra space in the container. This distinction becomes important when your layout wraps onto multiple lines, allowing you to fine-tune both item and line alignment in your flex layouts.

question mark

Which statements about cross axis alignment in flexbox are correct?

Select the correct answer

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 2

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

Suggested prompts:

Can you explain the difference between `align-items` and `align-content` with a visual example?

When should I use `align-items` versus `align-content` in my layout?

Are there any common mistakes to avoid when using these properties?

Awesome!

Completion rate improved to 7.69

bookCross Axis Alignment

Desliza para mostrar el menú

When you want to control how items are aligned along the cross axis in a flex container, you use the align-items property. This property determines how the flex items are positioned vertically (if your flex direction is row) or horizontally (if your flex direction is column) within the container. The most common values for align-items are:

  • flex-start: aligns items to the start of the cross axis;
  • flex-end: aligns items to the end of the cross axis;
  • center: centers items along the cross axis;
  • stretch: stretches items to fill the container (the default);
  • baseline: aligns items so their text baselines line up.

For containers that wrap onto multiple lines, the align-content property lets you control the spacing and alignment of the entire lines of items along the cross axis, rather than just individual items.

index.html

index.html

copy

In the example above, you see a flex container with three items. The container uses align-items: flex-end, which means all the items are aligned to the bottom of the container—the end of the cross axis. No matter what their heights are, the items' bottoms line up with the container's bottom edge. If you changed align-items to center, the items would be centered vertically within the container; with stretch, they would expand to fill the container’s height.

index.html

index.html

copy

It is important to understand the difference between align-items and align-content. The first example demonstrates align-items, which aligns all the flex items within a single line of the flex container. This affects the vertical placement of each item relative to the container's cross axis.

In contrast, the second example uses align-content with wrapping enabled. Here, the container has enough items to create more than one line. The align-content: space-around property distributes the lines of items evenly along the cross axis, adding space above, between, and below the rows of items. While align-items aligns items within each line, align-content manages the spacing between the lines themselves when there is extra space in the container. This distinction becomes important when your layout wraps onto multiple lines, allowing you to fine-tune both item and line alignment in your flex layouts.

question mark

Which statements about cross axis alignment in flexbox are correct?

Select the correct answer

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 2
some-alt