Introduction
Responsible application that works seamlessly with all devices like mobile, tablet, and desktops irrespective of size without breaking look and feel, and information.
Key points to consider while working on Responsive Applications
1. Viewport meta tag
The viewport is the area on the screen that is visible to the user. HTML5 introduced <meta> tag where we can set the viewport, which is suitable for all the devices.
<meta name="viewport" content="width=device-width, initial-scale=1.0"></meta>
This gives information to the browser on how to handle the width and scaling of the page according to the device where the application is loading.
Here, width=device-width adjusts the width of the page
initial-scale=1.0 helps the browser set the scaling and zoom level of the page when the page is first loaded by the browser.
2. Usage of CSS
Use @media queries for all the breakpoints: Write styles for smaller screens first and then for larger screens using @media.
/* When screen size larger than 600px */
@media (min-width: 600px) {
body {
background-color: lightblue;
}
}
/* When screen size smaller than 600px */
@media (max-width: 599px) {
body {
background-color: lightyellow;
}
}
We can specify the range of screen sizes as below:
/* Specific range of screens */
@media (min-width: 600px) and (max-width: 1024px) {
body {
margin: 20px;
}
}
Along with these, we can use ‘orientation: landscape/portrait’ for horizontal/vertical screens.
Also, we can use the required font styles or display/hide specific elements with @media.
/* font styles */
@media (min-width: 600px) {
body {
font-size: 1.2em;
}
}
An
/* display hide and show with @media */
@media (min-width: 600px) {
.Classname {
display:none;
}
}
Grid view: Web pages can be divided into 12 columns and 100% of width. This will help us place the elements on the page easily and responsively.
This is how the grid classes are defined.
.col-1 {width: 8.33%;}
.col-2 {width: 16.66%;}
.col-3 {width: 25%;}
.col-4 {width: 33.33%;}
.col-5 {width: 41.66%;}
.col-6 {width: 50%;}
.col-7 {width: 58.33%;}
.col-8 {width: 66.66%;}
.col-9 {width: 75%;}
.col-10 {width: 83.33%;}
.col-11 {width: 91.66%;}
.col-12 {width: 100%;}
And in the html file, we can add the following:
<div class="row">
<div class="col-3">Div details goes here</div> <!-- 25% width of total page-->
<div class="col-9">Div details goes here</div> <!-- 75% width of total page-->
</div>
Bootstrap or tailwind CSS: Bootstrap allows coders to create user-friendly and mobile-friendly applications with less effort. It provides pre-designed styles for components, utilities, and grid systems to help achieve responsiveness.
We can include Bootstrap in our coding platform via CDN or by installing it with the npm command.
Bootstrap’s Grid system looks like as below:
<div class="container">
<div class="row">
<div class="col-md-6 col-lg-4">Column 1</div>
<div class="col-md-6 col-lg-4">Column 2</div>
<div class="col-md-6 col-lg-4">Column 3</div>
</div>
</div>
Here, the classes work for different breakpoints, as explained below:
- col-sm: For small devices (≥576px)
- col-md: For medium devices (≥768px)
- col-lg: For large devices (≥992px)
- col-xl: For extra-large devices (≥1200px)
Tailwind CSS: This is an open-source CSS framework that provides a list of utility CSS classes directly in HTML files, so it eliminates custom styling. Meanwhile it reduces work for coders as well.



Join the conversation! Your thoughts help the community grow.