What are Flexbox & Grid? Flexbox and grid are new CSS layout techniques. Flexbox and grid are different approaches to laying out content and can be used together. While grid is newer, it does not replace flexbox. There are scenarios in which you could use both, so both are useful to know.
On the CSS Tricks article What’s the Difference Between Flexbox and Grid? Beverly @aszenitha commented “Use grid when you already have the layout structure in mind, and flex when you just want everything to fit. Layout first vs content first.”
Flexbox, Grid, & Bootstrap Explained
Let’s look at what each of these three things is, when to use them, and how they relate to each other.
What is CSS Flexbox?
CSS flexbox is primarily used when laying out webpage content in one direction (row or column). We say primarily because flexbox content can wrap, which would create multiple rows and columns. Its focus is not on creating a full grid though, as CSS grid does.
We use flexbox to size, align, and distribute content in a direction (row or column). In a world of various sized devices, the flexibility of flexbox enables us to size content for different size screens, to change from a column direction on mobile to a row direction on desktop, and to even reorder content differently on multiple screen sizes.
What is CSS Grid?
Grid is the first CSS technique that lets you define a grid of columns and rows onto which you place the content of your webpage. You can place the content into an area of the grid regardless of the HTML source order, and the grid can be completely different on various screens sizes! This enables you to build responsive webpages that adapt to screen size in a much better (and easier) way than we could previously. Reordering content according to screen size is much easier with grid.
If you’re new to coding you may not appreciate just how revolutionary grid is and why web developers are so excited about it. Compared to the ways we previously coded webpage layouts, grid changes everything. It works very differently than CSS floats, display as inline, and tables (from the early days of the web), etc. It gives us the ability to create more interesting and attractive layouts, with less code that’s more intuitive to work with.
What is Bootstrap?
Behind the scenes, Bootstrap 4 is based on Flexbox. If you’re used Bootstrap 3, version 4 made some fairly major changes to the way it works. It’s not a drop-in replacement and you will need to understand how flexbox works to fully understand and utilize Bootstrap 4.
CSS flexbox and grid are making it easier for developers to create layouts quickly. That means some developer will use flexbox and grid instead of Bootstrap. Other developers (especially back-end) are not as good with CSS and will, therefore, continue to choose Bootstrap because it’s quick and easy to use. You will likely encounter sites built with Bootstrap (especially many WordPress themes), so Bootstrap is a useful thing to know and include on your resume.
About This Class
If you already know some HTML and CSS, but have not learned Flexbox and Grid yet, this class is perfect to get you up and running quickly.
If you’re just getting started coding webpages, this class is part of the core web curriculum of our web development certificates. That means you’ll learn these concepts in each of these certificate programs: