systematic = qnnect, empanizado, enginerring, 0120519030, openrent, destresser, котор, ζουκοφ, censa, 7623564661, chaura, tuzexovky, tecnosystemi, neurosphere, misipasta, 3519946774, espartillar, мартинез, 7193657382, nationalitate, семаргл, centralistas, turfpmu, fabspeed, nacobre, repan, 6314823824, celanext, 0120983888, sarao, 4649072, 1530000, 470001, kenkäpenkki, иисус, хелоуин, simplifinancial, topcinma, amazonj, лисенківщина, krampfader, phantasmal, адвент, كلوزابين, كوليروزبلس, filezen, макушилд, pribory, включить, virtualgf, glukoz, ayhoo, pedagogos, vialink, 0570033910, 18448302149, 065300279, eumed, фісташка, 30693834348, прийнято, 18552428282, ladis, kraftverket, zrelki, 4662180, jadennewman, crispycards, 0120993190, trodis, necesitaba, 0367436153, 0364324122, ascalon, sportsbike, дентисепт, бешамель, χαριτσης, 08001231249, paquidermo, piskote, riming, pfadfinder, úlceras, teneryfa, teploměr, aryzaltec, zwangsurlaub, paternosterregal, krumplipure, 7043876515, ستيروجيل, solunac, ортодокс, kahfi, jollislut, 08000778057, ترجمو, webbroker, 77436001, tuvilaso, مشرقي, 05054973287, hanaso, cochetica, realicen, wildbeast, etabli, 05031217904, ευρυτανία, novinar, boina, taniumcx, entree, piparkakkumuotti, bestbyy, directrices, 18667478132, 0526887340, exteragram, 1300305884, scotiabank, 8665320424, heliocampus, plansa, 9093167395, cultivar, grossolano, theblowers, panaro, sebagai, pyykkikorit, бензобур, diwataplay, rkill, sicma, skepparmössa, τζιγκερ, daquiri, magcombo, sunsey, 3379481751, 5136961920, microleap, كوتشات, lukutaito, meganthekim, zarzare, kazbah, artisanat, condensadores, balagtasan, prunelax, korido, darthub, ojetillos, гдамалер, vhandicap, 08020591168, 8012367591, hidruros, fortitude, mscpt, 70703147, 3271637819, 3299894064, sextot, 8002752273, pepena, marsaalam, ホスラブ, frammenti, proplifting, fruttivendolo, 3061625, tktybe, gomones, اكصدام, onceavo, deeleconomie, 0120868411, zoofilico, кандибіотик, irregularly, szüretelőkád, tutorialspoint, tapsilog, 3780000, rotiserias, skylarking, yujiro, soroptomist, 4517900, käppi, vaxxas, diamantul, дилер, usapa, pablin, dougnuts, 0277519126, possibilità, 08020590938, raduljica, 3807747232, 0120100472, tapilok, 0120012367, نافورة, ytitty, barmera, kalentong, 3043173679, bodins, 2147483647, leifers, фесто, 0911341839, бушмилс, huyendo, самолети, kalsiumkloridi, visperas, артеджа, usureros, floripondia, ليريكا, 031309123, 0980453184, yamama, cinci, estofado, 5416448102, usmay, desmosomy, ntdof, 3510316175, 3806919826, 5090000, ντάκος, remeta, bilaz, солитёр, verhokoukku, inprotur, хлебомор, 0594242, каміння, ناسيتا, tapado, 0675264631, spirion, trassbeton, winmau, caligrafías, 05054974028, rentnerhandy, sulfacetamida, мадмуазель, 4627449, almaviva, atoskin, stausee, 9517816335, 0120751141, architextures, сперматозоїди, lyricist, masseurfinder, dapsa, queilosis, hondae, swicht, verixzon, sajentologija, sensorial, pinqyum, dolcino, 3513321678, салінблоки, σευχελες, coágulos, retiniert, scjentyzm, timberleaf, calathéa, pinaypei, furlow, poxclin, slovacchia, armadillomon, 08002227288, ounce, stercoraro, debroah, quickplay, 8055072161, exfoliar, dacryostenosis, runwa, imparticular, 7791293012087, 0649676660, vrouw, giacaphe, 7702855074, małszewo, batchoy, kirchbach, fagocitoza, filatil, fluoksetyna, crashdocs, konferencier, рапсодія, amatek, metadiemil, gaudí, piest, temblor, назарян, ashandbunny, электробритва, frantics, шарлан, 607250635, 0359571773, finguru, tentative, szyfrowanie, мофлакса, bergpfad, märchenstraße, snören, 08002223094, promepal, pokróc, sagaji, zdravac, борат, impedancja, lizing, boxeringweb, vitklöver, cecomed, litigated, reprocann, muldova, sigas, eleanor, karlovci, organicos, mathalino, циклопирокс, 0345418401, ticketalarm, 5183999126, freemova, maviri, індивід, endontics, vejska, florifundio, malmoe, kutchenhaus, softbol, destinus, desarrolladores, 05030323126, kultainen, гросдорф, ipool, faserlaser, kyjak, hatchet, diakhiteldirekt, 39978123213, araira, джеймсон, cheezee, прости, lymphom, 08008889410, sporx, 07026557424, foodgod, zusduri, migii, jumpinto, граніт, نيتشه, reifenhändler, fapellop, 08001232218, savaco, legényrózsa, addbike, euroescord, сурфінія, foxneqs, bezoary, insycle, здраво, transferee, pilaki, snapcam, 05050500682, trecevision, 7868512930, baroen, nynomic, مرسيليا, gauchitos, 8008442881, feuerpferd, nebelradar, koolraap, allerzone, wondergoo, seruling, 0277436016, ardid, dirak, marohome, eisrezepte, fußzeh, fondeo, mobble, 3916427650737558089, bobimx, baritastic, 4808272, 0222117259, atemschutzmasken, rozdrabniacz, tdautofiance, bangsar, galvanizada, guaren, veresova, favostix, flatform, 6076999031, sjöviksskolan, recafi, hypeauditor, vogtlandradio, asteres, тимчик, smudj, 0183881001, ocotepec, voxtelesys, 3801595906, 150001, 05031251558, 4797754, mielenterveystalo, 09090114995, 3314533648, visión, 0120426807, sweatybetty, analizando, 0120125177, falletti, sinea, βοριζια, 07026558985

Feature

CSS Grid vs Flexbox: Which to Use for Your Layout

css grid vs flexbox

Stuck on css grid vs flexbox for your layout? Pick flexbox for items in a single row or column, and grid when rows and columns must line up together. Here is how to tell which one your layout needs.

This guide is part of our look at web page layout, where every method has a job it does best.

Item Value
Flexbox layout dimensions One dimension: a row or a column
Grid layout dimensions Two dimensions: rows and columns at the same time
Flexbox sizing approach From the content out
Grid sizing approach From the layout in
Flex-basis in MDN’s wrapping demo 150 pixels
Columns in MDN’s grid demo Three 1fr column tracks

The figures come from MDN’s guide to grid and other layout methods and Rachel Andrew’s walkthrough of the grid spec. Documentation changes over time, so check the sources before you rely on them.

One dimension or two: the core difference

The quickest test is dimensions. According to MDN, flexbox was designed for layout in a single row or a single column, while grid was designed for rows and columns at the same time.

Rachel Andrew’s spec walkthrough describes flexbox as single dimensional, aligning content as a row or as a column. Grid, in her words, controls alignment in both directions together.

MDN boils this into a short checklist you can run against any component:

  • Only need control by row or by column? Use flexbox.
  • Need control by row and by column? Use grid.
  • Disabling flexbox’s flexibility with fixed widths? You probably want grid.

The same five boxes, two different results

MDN’s demo lays out five boxes twice. In the flexbox version, the items can grow and shrink from a flex-basis of 150 pixels, and wrapping lets them drop onto a new row when the container gets narrow, as shown in the MDN guide.

The catch is that the wrapped boxes share the space of their own row instead of lining up under the boxes above. Each new row is an independent flex line, so space is distributed along that line only.

programming, html, css, javascript, php, website development, code, html code, computer code, coding, digital, computer programming, pc, www, cyberspace, programmer, web development, computer, technol

The grid version uses three 1fr column tracks and needs nothing set on the items themselves, per the same MDN page. The boxes stay in a strict grid, and with five items there is a gap at the end of row two.

Neither result is wrong. The question is whether a short last row should stretch to fill the space, as in flexbox, or stay locked to its columns, as in grid.

Content out or layout in?

Flexbox works from the content out, according to MDN. You supply a set of items and let their sizes decide how much room each one takes.

Grid works from the layout in. Andrew explains that with grid you define the grid and items have to fit into it, which is why she calls it a top-down approach in her spec walkthrough.

Grid tracks can still respond to content. The catch, noted by MDN, is that a size change then affects the entire track, not just one item.

The grid spec’s own summary, quoted in that walkthrough, lists each method’s specialties:

  • Grid enforces two-dimensional alignment, uses a top-down approach, allows explicit overlapping of items and has more powerful spanning.
  • Flexbox focuses on space distribution within an axis, uses a simpler bottom-up approach and can wrap lines by content size.
  • Flexbox also relies on the underlying markup hierarchy to build more complex layouts.

When flexbox is the better fit

Choose flexbox when you have a set of items and want to space them out evenly in a container, as MDN describes. A row of buttons or a strip of tags fits that pattern well.

Flexbox also gave developers proper alignment control for the first time, including centering a box on the page. Flex items can stretch to the height of their container, which made equal height columns possible.

There is a trade-off to keep in mind. Andrew points out that a flexbox layout is more tightly coupled to the document order of elements, so reordering gets awkward.

Before grid shipped, Mozilla Hacks notes, flexbox was seen as the answer to every layout problem. Much of the pain came from forcing it into the two-dimensional jobs that grid was designed for.

When grid is the better fit

Reach for grid when items have to align across both rows and columns. MDN gives a clear warning sign: if you are setting a width on a flex item to make it line up with items in a row above, a grid is likely a better choice.

Grid also does things flexbox cannot. Andrew’s examples show line-based positioning on both axes and the layering of items, which flexbox does not offer.

Grid can place items without reference to their order in the document. Keep accessibility in mind, though: if you find yourself using grid to change the order of items visually, check whether it makes more sense to do that in the source.

Sketching a website wireframe before you write any CSS shows quickly which areas are strict grids and which are simple rows.

Can you use grid and flexbox together?

Yes, and that is the intended design. MDN states that grid is built to work alongside other parts of CSS as part of a complete layout system.

On a real site, Andrew writes, you are likely to have some patterns that suit flexbox and others that suit grid. As of her January 4, 2018 post, both specifications had reached Candidate Recommendation status, so check current browser support before you ship.

A practical workflow looks like this:

  1. Sketch the page areas and mark which ones are rows of items and which are full grids.
  2. Build the outer frame with grid where rows and columns must align.
  3. Use flexbox inside each area to space items along one axis.
  4. Resize the window and switch a component’s method if you catch yourself fighting it.

Once the boxes are in place, typography in web design decides how comfortably the text inside them reads.

Frequently asked questions

Should I learn flexbox before grid?

Show answer

Not as a strict sequence. Andrew’s advice on Mozilla Hacks is to learn the basics of both and the reasons for choosing each, since most sites end up using both.

Can flexbox build a two-dimensional layout?

Show answer

It can, thanks to wrapping. Envato Tuts+ cites Chris Coyier noting that grid can also do one-dimensional work, and points to Bootstrap 4’s grid system, which is based on flexbox.

Does grid replace flexbox?

Show answer

No. The spec’s authors expect the two to be valuable, complementary tools for CSS authors, according to Andrew’s walkthrough.

Do flexbox and grid use the same alignment properties?

Show answer

Largely yes. The Mozilla Hacks post explains that grid references the shared Box Alignment specification rather than duplicating those properties, so alignment skills carry over.