Web Developer Portfolio | Shrikant Bodke

CSS Grid: A Smarter Way to Build Web Layouts

If you’ve ever struggled with clunky layouts or spent hours messing with floats and margins, CSS Grid might be the solution you’ve been waiting for. It lets you build layouts using rows and columns, without the usual CSS chaos. In this post, I’m walking you through the basics of CSS Grid and how it makes web design way easier and more organized.


1. Starting With a Basic Grid Layout

To begin, just set display: grid; on your container. You can then define how many columns or rows you want. No need for weird hacks or float fixes.

Here’s a basic setup:

.container {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 10px;
}

.item1 {
  grid-column: 1;
}

.item2 {
  grid-column: 2;
}
<div class="container">
  <div class="item1">Item 1</div>
  <div class="item2">Item 2</div>
</div>

That gives you two columns—one narrow, one wide. It’s clean, readable, and super easy to tweak later.


2. Making It Responsive (Without Media Queries)

One of the things I really like about CSS Grid is how flexible it is for responsive layouts. You don’t always need media queries to adjust things for different screen sizes.

Try this:

.container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
}

Each column will be at least 100px wide and will scale automatically depending on the screen size. Whether someone’s using a desktop or a phone, the layout adjusts on its own.


3. Naming Grid Areas for Better Code Structure

Want your layout to be more readable, especially when you’re working on bigger projects? You can name your grid areas like header, main, sidebar, and footer. It helps a lot when organizing your CSS.

.container {
  display: grid;
  grid-template-areas:
    "header header"
    "main sidebar"
    "footer footer";
}

.header {
  grid-area: header;
}

.main {
  grid-area: main;
}

.sidebar {
  grid-area: sidebar;
}

.footer {
  grid-area: footer;
}
<div class="container">
  <div class="header">Header</div>
  <div class="main">Main Content</div>
  <div class="sidebar">Sidebar</div>
  <div class="footer">Footer</div>
</div>

Now your code clearly shows which section goes where. It’s just easier to maintain and understand.


Final Thoughts

CSS Grid has completely changed how I approach layout design. It’s neat, powerful, and takes a lot of pain out of building responsive pages. If you haven’t used it yet, give it a shot in your next project. You’ll probably wonder how you ever did layouts without it.