Welcome to a tutorial on how to create a responsive list/grid view. Once upon a time in the Dark Ages of the Internet, we have to use all sorts of CSS hacks and fight digital dragons to transform a list into a grid. But rest easy, modern CSS is very easy to work with. Let us walk through a simple list/grid example in this guide, read on!
ⓘ I have included a zip file with all the source code at the start of this tutorial, so you don’t have to copy-paste everything… Or if you just want to start quickly.
TLDR – QUICK SLIDES
Fullscreen Mode – Click Here
TABLE OF CONTENTS
DOWNLOAD & DEMO
Firstly, here is the download link to the example code as promised.
QUICK NOTES
If you spot a bug, feel free to comment below. I try to answer short questions too, but it is one person versus the entire world… If you need answers urgently, please check out my list of websites to get help with programming.
EXAMPLE CODE DOWNLOAD
Click here to download the source code in a zip file – I have released it under the MIT License, so feel free to build on top of it if you want to.
LIST/GRID VIEW DEMO
HTML CSS LIST GRID VIEW
All right, let us now get into more details on how the list/grid view works in this section.
PART 1) THE HTML
<!-- (A) ITEMS LIST/GRID -->
<ul id="demo">
<li>Item A</li>
<li>Item B</li>
<li>Item C</li>
<li>Item D</li>
<li>Item E</li>
</ul>
<!-- (B) VIEW SWITCHER -->
<button onclick="document.getElementById('demo').className=''">
⊟
</button>
<button onclick="document.getElementById('demo').className='grid'">
⊞
</button>
Yep, that’s all we need for the HTML.
- Just a “regular” HTML list.
- Buttons to switch between list and grid view.
PART 2) LIST VIEW CSS
/* (A) LIST VIEW BY DEFAULT */
#demo {
/* (A1) REMOVE BULLETS & IDENTATION */
list-style: none;
padding: 0; margin: 0;
/* (A2) LIST VIEW - 1 ITEM PER ROW */
display: grid;
grid-template-columns: 100%;
grid-gap: 5px;
}
/* (B) LIST ITEMS */
#demo li {
padding: 10px;
border: 1px solid #ddd;
}
#demo li:nth-child(odd) { background: #f7f7f7; }
- (A1) The default list will come with bullet points and indentations, we simply remove them here.
- (A2) The magic behind the list/grid view is actually
display: grid
. This is set togrid-template-columns: 100%
, effectively a single-column list. - (B) Just some cosmetics for the list items.
PART 3) GRID VIEW CSS
/* (C) GRID VIEW - 3 ITEMS PER ROW */
#demo.grid {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
- Remember the HTML buttons above? They toggle a
.grid
CSS class on the list. - To transform the list into a grid, we simply set
#demo.grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
. This turns it into three columns per row, and that’s all to the “grid view”.
EXTRA BITS & LINKS
That’s all for this guide, and here is a small section on some extras and links that may be useful to you.
LINKS & REFERENCES
- CSS Grid – MDN
- Example on CodePen – List/Grid View
TUTORIAL VIDEO
INFOGRAPHIC CHEAT SHEET

THE END
Thank you for reading, and we have come to the end of this tutorial. I hope it has helped you to create a better project, and if you want to share anything with this guide, please feel free to comment below. Good luck and happy coding!
thank you for this article, really helped me