Material-UI Grid Breakpoints
Tags: materialui, breakpoints, grid
Published: 2020-01-04 20:11:43

# Introduction

This is a tutorial on how to set breakpoints for your Material UI grid.
Breakpoints match with a certain screen width and depending on what value you set is how many cards will occupy the space given the amount of available space.  

xs, extra-small: 0px
sm, small: 600px
md, medium: 960px
lg, large: 1280px
xl, extra-large: 1920px

Here is a grid item from Material-UI: 
```javascript
<Grid item xs={A} sm={B} md={C} lg={D} xl={E}>
    <Paper className={classes.paper}>My Grid Item!</Paper>
</Grid>
```

Material-UI's grid is based on a 12 column system meaning the screen at any given point has 12 columns of available space. When you change a value at ABCDE it will tell the item, "Hey, let's take up X amount of columns with this one grid item at this breakpoint!" This allows us to set up the grid in so many unique ways based on how we set the values for each breakpoint. Below I will list out some examples and their output!

Here is a sandbox provided by Material-UI that you can play along in! <a href="https://codesandbox.io/s/l8z4m">Grid Sandbox</a> (Remember to navigate to demo.js to change the values of the grid items.)

#Examples

<img width= "700" height="500" src="https://thepracticaldev.s3.amazonaws.com/i/1qtm3v7e59yf3fxk3e40.png"/>

- In the above example we have the first row which is a grid item - xs(12) meaning it will always take all 12 of the columns at any screen size. 
- The second row has two grid items - xs(12), sm(6) meaning at screen size small and larger (width: 600px+) each card will take up half the screen (2 cards x 6 columns each = 12 columns total) and at size x-small (width:0-600px) the card will take 12 columns, or the full screen.
- The third row has 4 grid items - xs(6), sm(3) meaning at screen size small and larger (width: 600px+) each card will take up 1/4th of the screen (4 cards x 3 columns each = 12 columns total) and at size x-small (width:0-600px) the card will take 6 columns, or half the screen. 

<b>NOTE:</b> Even if you decrease the width of the grid in the above image, the third row will never only have 1 card in it, because it is programmed to always have 2 cards for an x-small screen. An example of compressing the width to a super small screen is below. 


<img width= "400" height="400" src="https://thepracticaldev.s3.amazonaws.com/i/kfheywo0bo7e32nr5l52.png"/>

You also do not need to have the 12 columns equally distributed between the cards in the row. If you had a grid item - xs(12), sm(9) and another grid item - xs(12), sm(3), they will be able to share the same row and take up 9 columns and 3 columns respectively, here is an image of this below.

<img width= "700" height="400" src="https://thepracticaldev.s3.amazonaws.com/i/jiee02m78a07lojy5lie.png"/>

Take note, if you distribute your cards without adding to 12 columns, the cards will not full take up the row and you'll be left with some extra space on the right-hand side like below.

<img width= "700" height="400" src="https://thepracticaldev.s3.amazonaws.com/i/cxbahidciaya4vbwv2me.png"/>


<i>Author's Note: Thanks for reading, guys! I had a hard time find a good resource to learn how to create this grid and the explanation on Material-UI wasn't enough for me so after playing around on the sandbox I created my own tutorial! Enjoy! </i>