Building responsive layouts with Grid
Creating a complete responsive website webpage layout using CSS grid in HTML web page is an easy and powerful method. Where web developers can easily develop the desired web page layout structure with the help of CSS using flexible grid properties features and media query elements as per their web development project needs. Which automatically customizes and adjusts according to the different modern screen sizes and electronic device gadgets available at present.

CSS Grid Container in HTML Web Page Creating Basic Responsive Grid Layout.
So let us now understand all the aspects of creating a responsive webpage website layout structure in a better way in HTML web page. Which automatically adjusts and displays based on your device screen viewport size.
Basic HTML Responsive Web Page Example.
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<title>Let Tray Responsive Css Grid Container Example</title>
<style>
* {
box-sizing: border-box;
}
body {
font-family: times new roman;
font-size: 20px;
font-weight: bold;
margin: 4;
padding: 4;
}
.grid-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); /* create a 170px responsive column */
gap: 14px; /* set display Space between grid items */
padding: 20px;
}
.grid-item {
background-color: teal;
color: white;
border: 1px solid yellow;
padding: 18px;
text-align: center;
}
</style>
</head>
<body>
<div class=”grid-container”>
<div class=”grid-item”>Home</div>
<div class=”grid-item”>Blog</div>
<div class=”grid-item”>Pages</div>
<div class=”grid-item”>About Us</div>
<div class=”grid-item”>Contact Us</div>
<div class=”grid-item”>Disclaimers</div>
</div>
</body>
</html>
Css Grid Container Code For Responsive Web Page.
* {
box-sizing: border-box;
}
body {
font-family: times new roman;
font-size: 20px;
font-weight: bold;
margin: 4;
padding: 4;
}
.grid-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); /* create a 170px responsive column */
gap: 14px; /* set display Space between grid items */
padding: 20px;
}
.grid-item {
background-color: teal;
color: white;
border: 1px solid yellow;
padding: 18px;
text-align: center;
}
Use of media query in css in HTML web page.
The web page structure you create in HTML can be displayed in a responsive web layout by using media queries in CSS to automatically adjust and preview the CSS grid container layout structure for better display on different device screen sizes.
@media (max-width: 700px) {
.grid-container {
grid-template-columns: 1fr; /* display single column layout */
}
}
@media (min-width: 400px) and (max-width: 800px) {
.grid-container {
grid-template-columns: repeat(2, 1fr); /* create two column for small screen */
}
}
Grid setup in CSS.
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)) – This creates a responsive grid container layout as per the web developer’s requirement where each created grid column is at least 180px wide. If there is any extra space left, the grid columns automatically fill the available grid area.
Using media queries in CSS grid container.
Where the first media query previews the grid in a column order on device screens smaller than 500px as per the current web page requirement.
The second grid media query defines a two-column layout for device screens between 400px and 800px.
So let’s understand the CSS media query source code in HTML web page.
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<title>Let Tray Responsive Css Grid Container Example</title>
<style>
* {
box-sizing: border-box;
}
body {
font-family: times new roman;
margin: 7;
padding: 7;
}
.grid-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
gap: 14px;
padding: 14px;
}
.grid-item {
background-color: orange;
color: white;
border: 1px solid black;
padding: 17px;
text-align: center;
}
@media (max-width: 800px) {
.grid-container {
grid-template-columns: 1fr; /* create a single column layout for small screen */
}
}
@media (min-width: 400px) and (max-width: 800px) {
.grid-container {
grid-template-columns: repeat(2, 1fr); /* create two column for small screen */
}
}
</style>
</head>
<body>
<div class=”grid-container”>
<div class=”grid-item”>Home</div>
<div class=”grid-item”>Blog</div>
<div class=”grid-item”>Pages</div>
<div class=”grid-item”>About Us</div>
<div class=”grid-item”>Contact Us</div>
<div class=”grid-item”>Disclaimers</div>
</div>
</body>
</html>
Responsive CSS web page with grid container in HTML web page.
Using grid with CSS media query in CSS grid container in HTML web page allows you to create a multi-purpose and responsive website web page layout structure that previews and functions properly on many devices and electronic gadgets available today. Here you can customize them in many ways according to your web design needs according to the grid properties.