Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk5 min

CSS Flexbox: A Practical Guide

A practical CSS Flexbox guide to containers, axes, alignment, wrapping, flexible sizing, choosing Grid, and debugging everyday layouts.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

CSS Flexbox arranges items along one axis at a time, making it a practical choice for navigation bars, toolbars, and other layouts where elements need to share space in a row or column. Set display: flex on a parent, then use axis-aware alignment, wrapping, and sizing rules to control its children.

How Flexbox works: containers, items, and axes

A flex layout begins with a parent element set to display: flex or display: inline-flex. Its in-flow children become flex items. The parent is the flex container; the children are the items it arranges.

Flexbox is one-dimensional. The container’s flex-direction sets its main axis, and the cross axis runs perpendicular to it. The default direction is row, so the main axis follows the row direction and the cross axis runs across it. With column, those roles turn: the main axis follows the column direction.

Thinking in terms of main and cross axes is more reliable than equating a property with “horizontal” or “vertical.” Direction can change, and writing modes can affect how row and column directions map to the screen.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

A small navigation example

Here, the nav is the container and its links are flex items:

<nav class="site-nav">
  <a href="/">Home</a>
  <a href="/guides">Guides</a>
  <a href="/about">About</a>
</nav>
.site-nav {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 1rem;
}

For a quick visual check, inspect the nav in your browser’s developer tools. Confirm that the parent has a flex layout and identify which children are items. Change flex-direction from row to column and watch which axis changes. MDN’s Flexbox learning guide assumes basic HTML and CSS knowledge.

How to space and align flex items

Use justify-content to distribute items along the main axis. Use align-items to align them along the cross axis. The relevant screen direction depends on flex-direction; these properties are not fixed synonyms for horizontal and vertical alignment.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

This places the toolbar items along its main axis with space between them and aligns them across the cross axis. The gap property adds spacing between items without adding margins to their outside edges. Use align-self on an individual item when it needs a different cross-axis alignment from the container’s other items.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Center a component

To center a child both across and along the available space, give the parent a definite height and use both alignment properties:

.stage {
  min-height: 20rem;
  display: flex;
  justify-content: center;
  align-items: center;
}

With the default row direction, justify-content centers along the row’s main axis and align-items centers across it. If you switch the direction to column, the axes—and therefore the properties’ roles—switch too.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

How to wrap items onto multiple lines

Flex items stay on one line by default. Set flex-wrap: wrap when a row or column should continue on another line rather than force every item to remain on one line:

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

Each wrapped flex line is handled as a line in the cross direction. Wrapping is useful for groups such as tags or buttons, but it does not create a fully coordinated two-dimensional grid: items on different lines are not generally controlled as shared rows and columns.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The flex-flow shorthand combines direction and wrapping. For example, flex-flow: row wrap is equivalent to setting flex-direction: row and flex-wrap: wrap.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

How flexible sizing works

Flex items’ sizes are influenced by three properties:

  • flex-basis sets an item’s initial main-size basis before available space is distributed.
  • flex-grow sets how much an item can grow relative to other items when there is positive free space.
  • flex-shrink sets how much an item can shrink relative to other items when there is not enough space.

The flex shorthand combines these values. For example, flex: 1 1 12rem means a grow factor of 1, a shrink factor of 1, and a basis of 12rem. Items with equal grow factors share positive free space proportionally; the shorthand is not simply a fixed width.

Common shorthand values

Value Equivalent factors Practical effect
flex: initial 0 1 auto Does not grow, can shrink, and uses the item’s automatic basis.
flex: auto 1 1 auto Can grow and shrink, using the automatic basis.
flex: none 0 0 auto Does not grow or shrink, using the automatic basis.
A numeric factor, such as flex: 2 Grow factor 2, with a zero basis in the specification’s basic values Uses the factor to participate in distribution of available space.

The W3C specification describes the grow factor as determining an item’s relative share of positive free space and the shrink factor as controlling reduction when space is insufficient. Its current published CSS Flexible Box Layout Module Level 1 is a Candidate Recommendation Draft dated 14 October 2025; W3C cautions that this work-in-progress draft may be updated, replaced, or obsoleted. The specification’s abstract says: “The specification describes a CSS box model optimized for user interface design.”

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When to use Flexbox instead of Grid

Choose the layout method based on the relationships the design needs. MDN describes Flexbox as one-dimensional and Grid as two-dimensional: Grid controls rows and columns together.

Design need Usually the better fit Why
Arrange items in one row or one column, with flexible sizing or alignment Flexbox The items relate primarily along one axis.
Control a coordinated set of rows and columns together Grid The layout needs two-dimensional track control or explicit placement.
Let a sequence of items continue onto another line when space runs out Flexbox with wrapping Wrapping creates additional flex lines, not a shared two-dimensional track system.

For patterns where either method may work, compare the layout recipes in MDN’s CSS layout cookbook. A design can also use both: Grid for the overall page structure and Flexbox inside a component that lays out its contents in one direction.

How to debug a Flexbox layout

  1. Select the intended parent. In DevTools, check whether it has display: flex or display: inline-flex. If not, its children are not flex items for that layout.
  2. Check the direction and axes. Inspect the computed flex-direction. Work out which direction is the main axis before adjusting justify-content or cross-axis alignment.
  3. Check available space and wrapping. Inspect the container’s size and flex-wrap. If items unexpectedly overflow or remain on one line, check whether wrapping is enabled and whether the items can shrink.
  4. Inspect item sizing. Review each relevant item’s flex-basis, flex-grow, and flex-shrink, including any flex shorthand that sets them together.
  5. Change one value at a time. Use DevTools’ style editor to adjust the property and observe the result before changing another variable. This makes it easier to identify the rule responsible.

MDN’s CSS debugging guide covers browser developer tools and compatibility information. Check compatibility information for the browsers and features your project needs rather than assuming one browser’s behavior settles every case.

Or skip the browser setup

If you are building a guide or demo and need a screenshot of the result, ScreenshotNeo is a website screenshot API and MCP server. Its API can return an image or PDF from one GET request; the docs are at screenshotneo.com/docs/.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Cookie banners, popups, and chat widgets are removed before the shot. Bot checks, blank pages, and failed loads are never billed. An MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for free.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.