<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/css-flexbox-fundamentals-a-visual-guide-dlizlc3et" -->

---
title: CSS Flexbox Fundamentals: A Visual Guide | daily.dev
description: Flexbox arranges items along a main axis and a cross axis, and flex-direction picks which is which. justify-content spaces items along the main axis,...
canonical: https://daily.dev/posts/css-flexbox-fundamentals-a-visual-guide-dlizlc3et
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: CSS Flexbox Fundamentals: A Visual Guide | daily.dev
og:description: Flexbox arranges items along a main axis and a cross axis, and flex-direction picks which is which. justify-content spaces items along the main axis,...
og:url: https://daily.dev/posts/css-flexbox-fundamentals-a-visual-guide-dlizlc3et
og:image: https://api.daily.dev/og/posts/dlizlC3Et.png
og:image:alt: CSS Flexbox Fundamentals: A Visual Guide
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# CSS Flexbox Fundamentals: A Visual Guide

**[Kirupa](https://daily.dev/sources/kirupa)** · 15 min read · 0 upvotes · 0 comments

## Summary

Flexbox arranges items along a main axis and a cross axis, and flex-direction picks which is which. justify-content spaces items along the main axis, align-items lines them up across it, gap sets spacing, and flex-wrap moves overflow to a new line. The default align-items: stretch is why row items end up the same height. flex: 1 means flex: 1 1 0%, giving equal shares. Items won't shrink below their content by default, and min-width: 0 lets an item shrink past it. A navigation bar example uses an auto margin to push links to the far end.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.kirupa.com/html5/flexbox_fundamentals.htm>

## Questions this post answers

### Why are all my flex items the same height in a row?

The default value of align-items is stretch, which makes every flex item fill the container's cross axis. In a row, that means each item becomes as tall as the container, as long as no fixed height is set. Setting align-items to flex-start, or giving items a fixed height, keeps them at their natural height.

_Developers untangling CSS layout surprises like this follow Flexbox techniques on daily.dev._

### Why won't my flex item shrink when it contains a long URL or code block?

A flex item won't shrink below the size of its content by default, so a long URL or wide code block can push it wider than the container. Setting min-width: 0 on the item lets it shrink past its content, and the content can then wrap or scroll inside it.

_Anyone debugging overflow in CSS layouts can keep learning these gotchas on daily.dev._

### What does flex: 1 actually mean in CSS?

flex: 1 is shorthand for flex: 1 1 0%, setting flex-grow to 1, flex-shrink to 1, and flex-basis to 0%. Because every item starts from a size of zero, all items with flex: 1 split the whole container into equal shares and end up the same size, regardless of their content.

_Developers who want to master CSS layout shorthands can build that depth on daily.dev._

## Similar posts on daily.dev

- [How to Use Flex in Tailwind CSS and Justify Flex Items](https://daily.dev/posts/how-to-use-flex-in-tailwind-css-and-justify-flex-items-wigqmkowt) · freeCodeCamp · 2 upvotes · 0 comments
- [Alignment in CSS Grid Lanes](https://daily.dev/posts/alignment-in-css-grid-lanes-t2tubdqwc) · Patrick Brosset · 45 upvotes · 3 comments
- [CSS Centering: Grid vs. Flexbox vs. Anchor Positioning](https://daily.dev/posts/css-centering-grid-vs-flexbox-vs-anchor-positioning-owvk3qzxc) · Syncfusion · 10 upvotes · 1 comments
- [Flexbox Masonry Layout \(Explained with Math\) – Frontend Masters Blog](https://daily.dev/posts/flexbox-masonry-layout-explained-with-math-frontend-masters-blog-vq7cfp4yp) · Frontend Masters · 5 upvotes · 0 comments

---

Tags: [#webdev](https://daily.dev/tags/webdev), [#css](https://daily.dev/tags/css)

[View this post on daily.dev](https://daily.dev/posts/css-flexbox-fundamentals-a-visual-guide-dlizlc3et)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"CSS Flexbox Fundamentals: A Visual Guide","url":"https://daily.dev/posts/css-flexbox-fundamentals-a-visual-guide-dlizlc3et","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/css-flexbox-fundamentals-a-visual-guide-dlizlc3et"},"datePublished":"2026-11-30T21:55:35.931Z","dateModified":"2026-11-30T21:55:57.419Z","description":"Flexbox arranges items along a main axis and a cross axis, and flex-direction picks which is which. justify-content spaces items along the main axis,...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/22173ca3e0217dc769a52fe67f81977f?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/22173ca3e0217dc769a52fe67f81977f?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Kirupa","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Kirupa","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/ff2fdb4927d34b81bd07cd18d6049a98","url":"https://daily.dev/sources/kirupa"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/css-flexbox-fundamentals-a-visual-guide-dlizlc3et","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"webdev,css","timeRequired":"PT15M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Kirupa","item":"https://daily.dev/sources/kirupa"},{"@type":"ListItem","position":3,"name":"CSS Flexbox Fundamentals: A Visual Guide"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/css-flexbox-fundamentals-a-visual-guide-dlizlc3et#faq","mainEntity":[{"@type":"Question","name":"Why are all my flex items the same height in a row?","acceptedAnswer":{"@type":"Answer","text":"The default value of align-items is stretch, which makes every flex item fill the container's cross axis. In a row, that means each item becomes as tall as the container, as long as no fixed height is set. Setting align-items to flex-start, or giving items a fixed height, keeps them at their natural height. Developers untangling CSS layout surprises like this follow Flexbox techniques on daily.dev."}},{"@type":"Question","name":"Why won't my flex item shrink when it contains a long URL or code block?","acceptedAnswer":{"@type":"Answer","text":"A flex item won't shrink below the size of its content by default, so a long URL or wide code block can push it wider than the container. Setting min-width: 0 on the item lets it shrink past its content, and the content can then wrap or scroll inside it. Anyone debugging overflow in CSS layouts can keep learning these gotchas on daily.dev."}},{"@type":"Question","name":"What does flex: 1 actually mean in CSS?","acceptedAnswer":{"@type":"Answer","text":"flex: 1 is shorthand for flex: 1 1 0%, setting flex-grow to 1, flex-shrink to 1, and flex-basis to 0%. Because every item starts from a size of zero, all items with flex: 1 split the whole container into equal shares and end up the same size, regardless of their content. Developers who want to master CSS layout shorthands can build that depth on daily.dev."}}]}
```

