Getting Started with Your First HTML Page
A beginner’s walkthrough of basic HTML structure. We’ll cover tags, attributes, semantic markup, and how everything connects together.
Centering elements and arranging content becomes straightforward when you understand how flexbox works. Learn the core properties that solve most layout problems.
Before flexbox, aligning elements in CSS was frustrating. You’d use floats, absolute positioning, or weird margin hacks to center a simple box. It’s a pain when something that should be simple requires three different tricks.
Flexbox (flexible box layout) changes that. It’s a one-dimensional layout method — perfect for arranging items in a single direction, whether horizontally or vertically. Once you understand the main properties, you’ll wonder how you ever built layouts without it.
Flexbox handles spacing, alignment, and distribution automatically. No more calculating margins or fighting float bugs. You define how items should behave, and flexbox takes care of the rest.
You don’t need to memorize everything about flexbox. Most layout problems get solved with just four properties: display, flex-direction, justify-content, and align-items. These are your workhorse tools.
Activates flexbox on a container. Without this, nothing else works.
Sets the main axis: row (left-to-right), column (top-to-bottom), or reversed versions.
Distributes space along the main axis. Center, space-between, space-around — pick what you need.
Aligns items perpendicular to the main axis. Perfect for vertical centering when using flex-direction: row.
Here’s where flexbox shines. You’ll use it constantly for navigation bars, card layouts, hero sections, and footer content. Let’s walk through three patterns you’ll see everywhere.
Create a full-height section with content centered both horizontally and vertically. Set the container to min-height: 100vh, display: flex, flex-direction: column, justify-content: center, and align-items: center. Everything inside gets perfectly centered with almost no effort.
Navigation bars are easier with flexbox. Use flex-direction: row to arrange items horizontally. Add margin-left: auto to the last item to push it to the right. On mobile, switch to flex-direction: column. Flexbox handles the reflow automatically.
Container with display: flex, flex-wrap: wrap, and a gap. Each card gets flex: 1 1 300px (grow, shrink, base width). Cards automatically adjust their number per row depending on viewport width. No media queries needed for the basic setup.
You’ll run into the same problems everyone else does when learning flexbox. Good news — they’re all easy to fix once you know what’s happening.
The default is row (horizontal). If you want items stacked vertically, you must set flex-direction: column. Many beginners assume vertical is the default.
justify-content works along the main axis (left-right for rows, top-bottom for columns). align-items works perpendicular to it. Keep this straight and alignment becomes predictable.
Flex items shrink below their content size by default. Set flex: 0 0 auto or a specific width if you don’t want them shrinking. The flex shorthand (flex: 1) makes them grow equally.
You don’t need to redesign everything. Start small — convert one section to flexbox and see how it works. The learning curve is gentle if you start with simple layouts.
Choose a simple section — maybe your navigation bar or a row of three cards. This becomes your flex container.
Apply display: flex to your chosen container. Watch how the direct children immediately become flex items arranged horizontally.
Try different values: center, space-between, space-around. Watch how the spacing changes. This teaches you how justify-content really works.
Open your page on a phone. Change flex-direction: row to column in a media query. You’ll see instantly how flexible flexbox actually is.
This article provides educational information about flexbox layout concepts and best practices. While the techniques described are widely adopted and battle-tested, CSS specifications continue to evolve. Browser support is excellent for modern flexbox properties, but older browsers (Internet Explorer 10 and earlier) have limited or no support. Always test your layouts across your target browsers. For production projects, consider using a CSS fallback strategy if you need to support legacy browsers. This guide is informational — specific layout requirements for your project may differ.
Flexbox isn’t magic, but it feels like it when you first use it for centering or distributing space. The beauty is in the simplicity — once you internalize display, flex-direction, justify-content, and align-items, you can handle most layout situations without struggling.
Start with one small section. Apply these properties. Watch how items rearrange. That hands-on learning beats any amount of reading. You’ll be amazed at how much cleaner your CSS becomes once flexbox clicks.
Explore responsive design patterns and how media queries work with flexbox for layouts that adapt beautifully to any screen size.
Read the Responsive Layouts Guide