HTML
📌 What is Responsive Web Design?
Responsive Web Design is an approach that allows a website to automatically adapt to different screen sizes (desktop, tablet, and mobile devices).
The main goal is:
No matter which device the user uses, the website should appear readable, organized, and user-friendly.
To achieve this, the following techniques are commonly used:
- Viewport setting
- Flexible (responsive) images
- Media queries (different CSS rules for different screen sizes)
- Using different images for different devices
🔹 2. Viewport Setting
One of the fundamental steps in responsive design is setting the viewport. For this, the following meta tag is added inside the <head> section:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
The purpose of this tag:
- width=device-width → Sets the page width equal to the device’s screen width
- initial-scale=1.0 → Sets the initial zoom level to normal (100%) when the page loads
If this tag is not used, mobile devices shrink the page to fit the screen, making the content appear very small.
🔹 3. Responsive (Flexible) Images
Images should also adapt to different screen sizes.
a) Using percentage width
<img src="image.jpg" style="width:100%; height:auto;">
- The image fills the entire width of its container
- Height adjusts automatically
- However, it may enlarge the image and reduce quality
b) Using max-width
<img src="image.jpg" style="max-width:100%; height:auto;">
- The image never exceeds its original size
- It can shrink but does not enlarge
- This helps maintain image quality
c) Using different images for different screens
<picture>
<source srcset="small.jpg" media="(max-width: 600px)">
<source srcset="medium.jpg" media="(max-width: 1500px)">
<img src="large.jpg" alt="Description">
</picture>
- The browser selects the appropriate image based on screen size
- Smaller screens load smaller images
- This improves both performance and visual quality
4. Responsive Text Size
Text can also adapt to screen size:
<h1 style="font-size:10vw">Hello World</h1>
- The vw unit is based on viewport width
- 1vw = 1% of the screen width
- This allows text to scale dynamically with the screen size
5. Media Queries
Media queries allow you to apply different CSS rules based on screen size.
Example:
/* Large screens */
.left, .right {
float: left;
width: 20%;
}
.main {
float: left;
width: 60%;
}
/* Small screens */
@media screen and (max-width: 800px) {
.left, .main, .right {
width: 100%;
}
}
- On large screens, elements are displayed side by side
- On small screens, they stack vertically
- This ensures mobile compatibility
Media queries are one of the most important parts of responsive design.
6. General Logic (Example Explanation)
When creating a responsive page, the following structure is usually used:
- Build a flexible layout using Flexbox or Grid
- Use percentage or flexible values for sizing elements
- Control images with max-width
- Apply media queries for smaller screens
For example:
- On large screens, 3 columns appear side by side
- On small screens, each takes 100% width and stacks vertically
🎯 Short Summary
- The main idea of responsive design is:
- Making a website flexible so it looks good on all devices.
- To achieve this:
- Set the viewport
- Make images flexible
- Use media queries
- Build layouts with Flexbox or Grid
