-
Hajipur, Bihar, 844101
Responsive web design ensures that your website looks good on all devices—desktops, tablets, and mobile phones—by automatically adjusting layout, content size, and appearance based on screen size.
Provides better user experience
Improves SEO ranking (Google prioritizes mobile-friendly sites)
Works on any screen size (mobile, tablet, laptop, desktop)
Saves development time by using a single codebase
The first step in making a website responsive is setting the viewport.
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Images should resize automatically based on screen size.
<img src="banner.jpg" alt="Banner" style="max-width:100%; height:auto;">
Avoid fixed pixel sizes. Use percentages or relative units.
<div style="width: 50%;">This takes half of the screen width</div>
Media queries in CSS allow you to apply styles based on screen size.
/* Default for desktop */
body {
background-color: lightblue;
}
/* For devices smaller than 768px */
@media only screen and (max-width: 768px) {
body {
background-color: lightgreen;
}
}
Flexbox makes it easy to create flexible layouts.
.container {
display: flex;
flex-wrap: wrap;
}
.box {
flex: 1 1 300px;
margin: 10px;
}
Use em
, %
, or vw
for scalable text sizes.
h1 {
font-size: 5vw; /* 5% of the viewport width */
}
Start with styles for mobile and add media queries for larger screens.
/* Mobile styles */
body {
font-size: 14px;
}
/* Tablets and up */
@media (min-width: 768px) {
body {
font-size: 16px;
}
}
Q1. Add a viewport meta tag to your HTML document.
Q2. Create an image that resizes based on screen width.
Q3. Build a layout using percentage-based width.
Q4. Use Flexbox to create a two-column layout that stacks on small screens.
Q5. Write a media query that changes the background color for screens smaller than 600px.
Q6. Design a heading with vw
units so it scales with the screen.
Q7. Make a <div>
take full width on mobile and 50% on desktop.
Q8. Create a mobile-first style sheet and override it for tablets.
Q9. Use max-width
and height: auto
to create responsive images.
Q10. Use media queries to hide an element on mobile view.
Q1: What is the purpose of the viewport meta tag?
Q2: Which unit is best for responsive text size?
Q3: What does max-width: 100% do to an image?
Q4: Which CSS property helps in creating a flexible layout?
Q5: What is the breakpoint for tablets in media queries?
Q6: Which approach is best for modern responsive web design?
Q7: What happens without the viewport tag on mobile?
Q8: Which tag helps with responsive images?
Q9: How do you hide content on mobile using media query?
Q10: Which unit adjusts text based on the screen size?