DevToolBoxFREE
BlogAdvertise

CSS Flexbox 치트시트: 모든 속성을 예제로 설명

10분 읽기by DevToolBox

CSS Flexbox는 현대 웹 개발에서 가장 널리 사용되는 레이아웃 시스템입니다. 요소를 정렬, 배치, 재정렬하는 강력한 방법을 제공합니다. 이 완전한 CSS Flexbox 치트 시트는 모든 속성을 실용적인 코드 예제와 함께 설명합니다.

Flexbox 생성기로 레이아웃을 시각적으로 구축하기 →

컨테이너 속성

Flexbox는 플렉스 컨테이너에서 시작합니다. 부모 요소에 display: flex를 설정하세요.

display: flex | inline-flex

플렉스 컨테이너를 정의합니다.

.flex-container {
  display: flex;        /* block-level flex container */
}

.inline-flex-container {
  display: inline-flex;  /* inline-level flex container */
}

flex-direction

주축 방향을 설정합니다.

.container {
  /* Main axis: left to right (default) */
  flex-direction: row;

  /* Main axis: right to left */
  flex-direction: row-reverse;

  /* Main axis: top to bottom */
  flex-direction: column;

  /* Main axis: bottom to top */
  flex-direction: column-reverse;
}
ValueMain AxisVisual Layout
rowHorizontal (left to right)[1] [2] [3]
row-reverseHorizontal (right to left)[3] [2] [1]
columnVertical (top to bottom)[1] / [2] / [3]
column-reverseVertical (bottom to top)[3] / [2] / [1]

justify-content

주축을 따른 요소 배치를 제어합니다.

.container {
  display: flex;

  /* Pack items to the start (default) */
  justify-content: flex-start;
  /* Result: [1][2][3]              */

  /* Center items */
  justify-content: center;
  /* Result:       [1][2][3]        */

  /* Pack items to the end */
  justify-content: flex-end;
  /* Result:              [1][2][3] */

  /* Equal space between items */
  justify-content: space-between;
  /* Result: [1]     [2]     [3]   */

  /* Equal space around items */
  justify-content: space-around;
  /* Result:  [1]   [2]   [3]     */

  /* Equal space between and around items */
  justify-content: space-evenly;
  /* Result:   [1]   [2]   [3]    */
}

align-items

교차축을 따른 요소 정렬을 제어합니다.

.container {
  display: flex;
  height: 200px;

  /* Stretch to fill container (default) */
  align-items: stretch;

  /* Align to the top */
  align-items: flex-start;

  /* Align to the center */
  align-items: center;

  /* Align to the bottom */
  align-items: flex-end;

  /* Align by text baseline */
  align-items: baseline;
}
ValueBehavior
stretchItems stretch to fill the container height (default)
flex-startItems align to the top of the container
centerItems are vertically centered
flex-endItems align to the bottom of the container
baselineItems align by their text baseline

flex-wrap

요소의 줄 바꿈을 제어합니다.

.container {
  display: flex;

  /* All items on one line (default) — may overflow */
  flex-wrap: nowrap;

  /* Items wrap to next line when needed */
  flex-wrap: wrap;

  /* Items wrap in reverse order */
  flex-wrap: wrap-reverse;
}

/* Shorthand: flex-flow combines direction + wrap */
.container {
  flex-flow: row wrap;         /* same as flex-direction: row + flex-wrap: wrap */
  flex-flow: column nowrap;    /* column direction, no wrapping */
}

align-content

여러 줄일 때 줄 간격을 제어합니다.

.container {
  display: flex;
  flex-wrap: wrap;
  height: 400px;

  /* Pack lines to the start */
  align-content: flex-start;

  /* Center lines */
  align-content: center;

  /* Pack lines to the end */
  align-content: flex-end;

  /* Equal space between lines */
  align-content: space-between;

  /* Equal space around lines */
  align-content: space-around;

  /* Lines stretch to fill container (default) */
  align-content: stretch;
}

gap, row-gap, column-gap

플렉스 요소 간의 간격을 제어합니다.

.container {
  display: flex;
  flex-wrap: wrap;

  /* Equal gap in both directions */
  gap: 16px;

  /* Different row and column gaps */
  gap: 20px 12px;         /* row-gap: 20px, column-gap: 12px */

  /* Individual properties */
  row-gap: 20px;
  column-gap: 12px;
}

/* Example: card grid with gap */
.card-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
}
.card-grid > .card {
  flex: 1 1 300px;  /* grow, shrink, min 300px */
}

아이템 속성

이러한 속성은 개별 플렉스 아이템에 설정됩니다.

order

시각적 순서를 제어합니다. 기본값 0.

.item-a { order: 2; }  /* appears third */
.item-b { order: -1; } /* appears first */
.item-c { order: 0; }  /* appears second (default) */

/* Visual result: [B] [C] [A]
   DOM order:     A    B    C
   Sorted order: -1    0    2  */

flex-grow

요소의 확장 비율을 정의합니다. 기본값 0.

/* All items same size — share space equally */
.item { flex-grow: 1; }

/* Item B takes twice the extra space */
.item-a { flex-grow: 1; }
.item-b { flex-grow: 2; }
.item-c { flex-grow: 1; }
/* If 200px extra: A gets 50px, B gets 100px, C gets 50px */

/* Only item B grows to fill remaining space */
.item-a { flex-grow: 0; width: 100px; }
.item-b { flex-grow: 1; }
.item-c { flex-grow: 0; width: 100px; }
/* Result: [100px][    fill    ][100px] */

flex-shrink

요소의 축소 비율을 정의합니다. 기본값 1.

/* Default: all items shrink equally */
.item { flex-shrink: 1; }

/* Prevent an item from shrinking */
.sidebar {
  flex-shrink: 0;
  width: 250px;  /* stays at 250px even when container is small */
}

/* Item A shrinks twice as fast */
.item-a { flex-shrink: 2; width: 300px; }
.item-b { flex-shrink: 1; width: 300px; }
/* If 100px must be removed: A loses ~67px, B loses ~33px */

flex-basis

공간 분배 전 초기 크기를 설정합니다.

.item {
  /* Use item's content size (default) */
  flex-basis: auto;

  /* Fixed starting size */
  flex-basis: 200px;

  /* Percentage of container */
  flex-basis: 25%;

  /* Use content's intrinsic size */
  flex-basis: content;

  /* Zero basis — ignore content size for space distribution */
  flex-basis: 0;
}

/* flex-basis vs width:
   - flex-basis sets the initial size BEFORE grow/shrink
   - width sets a fixed size
   - flex-basis is relative to the main axis
   - If both are set, flex-basis wins */

flex (단축 속성)

flex-grow, flex-shrink, flex-basis의 단축 속성.

/* flex: <grow> <shrink> <basis> */

.item { flex: 0 1 auto; }    /* default: don't grow, can shrink, auto basis */
.item { flex: 1; }           /* same as flex: 1 1 0%  — grow equally */
.item { flex: auto; }        /* same as flex: 1 1 auto — grow based on content */
.item { flex: none; }        /* same as flex: 0 0 auto — fully inflexible */
.item { flex: 2; }           /* same as flex: 2 1 0%  — grows 2x */
.item { flex: 1 0 300px; }   /* grow, don't shrink, start at 300px */
ShorthandEquivalentUse Case
flex: 1flex: 1 1 0%Equal-width items
flex: autoflex: 1 1 autoItems size by content then share space
flex: noneflex: 0 0 autoFixed-size item (no grow or shrink)
flex: 0 1 autodefaultDefault behavior
flex: 1 0 300pxgrow from 300px, never shrinkResponsive card with min-width

align-self

컨테이너의 align-items를 개별적으로 재정의합니다.

.container {
  display: flex;
  align-items: flex-start;  /* all items at top */
  height: 200px;
}

.special-item {
  align-self: center;       /* this item centered vertically */
}

/* Values: auto | flex-start | flex-end | center | baseline | stretch */
.item-a { align-self: flex-start; }  /* top */
.item-b { align-self: center; }      /* middle */
.item-c { align-self: flex-end; }    /* bottom */
.item-d { align-self: stretch; }     /* full height */

일반적인 레이아웃 패턴

실제 프로젝트에서 가장 많이 사용되는 Flexbox 레이아웃 패턴.

요소 중앙 정렬

Flexbox로 중앙 정렬이 간단해집니다.

/* Horizontal centering */
.center-horizontal {
  display: flex;
  justify-content: center;
}

/* Vertical centering */
.center-vertical {
  display: flex;
  align-items: center;
  height: 100vh;
}

/* Perfect centering (both axes) */
.center-both {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

/* Alternative: center with margin auto */
.center-auto {
  display: flex;
  height: 100vh;
}
.center-auto > .child {
  margin: auto;  /* centers in both axes */
}

내비게이션 바

클래식 반응형 내비바.

/* Basic navbar: logo left, links right */
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  height: 64px;
}

.navbar .logo {
  flex-shrink: 0;
}

.navbar .nav-links {
  display: flex;
  gap: 24px;
  list-style: none;
}

/* Navbar with center section */
.navbar-3 {
  display: flex;
  align-items: center;
  padding: 0 24px;
}
.navbar-3 .left   { flex: 1; }
.navbar-3 .center { flex: 0; white-space: nowrap; }
.navbar-3 .right  { flex: 1; display: flex; justify-content: flex-end; }

카드 그리드

줄 바꿈이 있는 반응형 카드 레이아웃.

/* Responsive card grid */
.card-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
}

.card {
  flex: 1 1 300px;   /* grow, shrink, min 300px */
  max-width: 400px;
}

/* Cards with equal height */
.card-grid-equal {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
}

.card-equal {
  flex: 1 1 300px;
  display: flex;
  flex-direction: column;
}

.card-equal .card-body {
  flex: 1;           /* body fills remaining height */
}

.card-equal .card-footer {
  margin-top: auto;  /* footer pushed to bottom */
}

스티키 푸터

콘텐츠가 적어도 푸터가 화면 하단에.

/* Sticky footer layout */
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin: 0;
}

header {
  flex-shrink: 0;  /* fixed height header */
}

main {
  flex: 1;         /* takes all remaining space */
}

footer {
  flex-shrink: 0;  /* fixed height footer */
}

/* HTML structure:
   <body>
     <header>...</header>
     <main>...</main>
     <footer>...</footer>
   </body>
*/

홀리 그레일 레이아웃

클래식 3단 레이아웃.

/* Holy grail layout */
.page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page > header,
.page > footer {
  flex-shrink: 0;
}

.page > .content {
  flex: 1;
  display: flex;
}

.page .sidebar-left {
  flex: 0 0 200px;   /* fixed 200px left sidebar */
  order: -1;         /* appears first visually */
}

.page .main {
  flex: 1;           /* main content fills remaining space */
  min-width: 0;      /* prevent overflow */
}

.page .sidebar-right {
  flex: 0 0 200px;   /* fixed 200px right sidebar */
}

/* HTML structure:
   <div class="page">
     <header>Header</header>
     <div class="content">
       <main class="main">Main Content</main>
       <aside class="sidebar-left">Left</aside>
       <aside class="sidebar-right">Right</aside>
     </div>
     <footer>Footer</footer>
   </div>
*/

Flexbox vs Grid: 언제 사용할까

둘 다 강력하지만 다른 문제를 해결합니다.

Flexbox가 최적:

  • One-dimensional layouts (a single row or column)
  • Content-driven sizing (items determine their own width)
  • Dynamic, unknown number of items
  • Navigation bars and toolbars
  • Centering elements
  • Components where items should wrap naturally

CSS Grid가 최적:

  • Two-dimensional layouts (rows and columns together)
  • Layout-driven sizing (the layout dictates item sizes)
  • Complex page layouts with header, sidebar, content, footer
  • Overlapping elements in a grid
  • When you need precise control over both axes simultaneously
  • Dashboard-style layouts with varying card sizes
/* Combining Flexbox and Grid */
.page {
  display: grid;
  grid-template-areas:
    "header header"
    "sidebar main"
    "footer footer";
  grid-template-columns: 250px 1fr;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
}

/* Use Flexbox inside grid areas */
.page header {
  grid-area: header;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.page main {
  grid-area: main;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-content: flex-start;
}

브라우저 지원

Flexbox는 모든 최신 브라우저에서 우수한 지원.

FeatureChromeFirefoxSafariEdge
Basic Flexbox29+28+9+12+
flex-wrap29+28+9+12+
gap (in Flexbox)84+63+14.1+84+
row-gap / column-gap84+63+14.1+84+

Flexbox has over 99% global browser support. The only consideration is the gap property in flex contexts, which requires slightly newer browsers. For older browser support, use margins as a fallback:

/* Fallback for gap */
.container {
  display: flex;
  flex-wrap: wrap;
  margin: -8px;       /* negative margin to offset item margins */
}
.container > .item {
  margin: 8px;        /* acts like gap: 16px */
}

/* Modern approach with @supports */
@supports (gap: 16px) {
  .container {
    gap: 16px;
    margin: 0;
  }
  .container > .item {
    margin: 0;
  }
}

자주 묻는 질문

justify-content와 align-items의 차이는?

justify-content는 주축, align-items는 교차축을 제어합니다. flex-direction이 column이면 축이 바뀝니다.

Flexbox와 Grid 중 언제 어떤 것을?

Flexbox는 1D 레이아웃, Grid는 2D 레이아웃에 적합. 함께 사용하면 효과적.

플렉스 요소를 같은 너비로 만들려면?

모든 요소에 flex: 1을 설정. 필요하면 min-width: 0도 추가.

플렉스 요소가 축소되지 않는 이유는?

기본 min-width: auto가 축소를 방지합니다. min-width: 0을 설정하세요.

Flexbox에서 gap을 사용할 수 있나요?

네, 모든 최신 브라우저에서 Flexbox gap을 지원합니다.

CSS Flexbox는 현대 레이아웃에 필수입니다. 인터랙티브 도구로 연습하세요.

인터랙티브 Flexbox 생성기 사용하기 →

도움이 되었나요?

Stay Updated

Get weekly dev tips and new tool announcements.

No spam. Unsubscribe anytime.

Partner Picks

Sponsor this article

Place your product next to this developer topic with tracked clicks.

Ask about article sponsorship

This site uses cookies for analytics and to display ads. By continuing to browse, you agree. Privacy Policy