Lesson 15 of 2658%

(Progress persistence is disabled until Phase 9)

CSS
Beginner
15 min

Flexbox Introduction

Learn 1D layouts with Flexbox.

Learning Objectives

  • display: flex

Flexbox Introduction

Welcome to this lesson on Flexbox Introduction. CSS is powerful, and mastering flexbox introduction is essential for creating beautiful web applications.

Explanation

CSS (Cascading Style Sheets) dictates the presentation of the HTML document. When applying these rules, the browser calculates the computed styles and paints them to the screen.

Syntax / Structure

Here is a common CSS rule related to this concept:

.container {
  display: flex;
  flex-direction: row;
}

How to Center a Div with Flexbox

One of the most common questions in CSS is how to center a div. Flexbox makes this incredibly easy. You can easily learn how to center a div horizontally and vertically using just three lines of CSS.

CSS Flexbox Center Example

.center-box {
  display: flex;
  justify-content: center; /* Centers horizontally */
  align-items: center;     /* Centers vertically */
  height: 100vh;
}
Tip

Best Practice: Always try to keep your CSS organized and modular. Use classes instead of IDs for styling when possible!

Try It Yourself

Open the BrowserCode playground and test these CSS properties on real HTML elements. You can try building your own CSS flexbox layout example.

Key Takeaways

  • Be mindful of CSS specificity.
  • Modern CSS reduces the need for complex hacks.

Lesson Progress

Practice This TopicTake QuizBuild a CSS Project

Ready to practise?

Apply what you learned with a hands-on challenge.

Practise This Topic