HTML Responsive Design | Creating Adaptive Webpages

HTML Responsive Design ensures that webpages look good and function well on different devices, including desktops, tablets, and smartphones. By using flexible layouts, scalable images, and media queries, developers can create responsive designs that adapt to varying screen sizes and orientations.

Key Concepts of Responsive Design:

The grid adjusts based on screen size:

Example of a Responsive Layout:

Responsive Layout with Media Queries

<!DOCTYPE html>
<html>
<head>
<title>Responsive Layout Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
    .container {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
    }
    .item {
        background-color: #4CAF50;
        color: white;
        text-align: center;
        padding: 20px;
    }
    @media (max-width: 768px) {
        .container {
            grid-template-columns: repeat(2, 1fr);
        }
    }
    @media (max-width: 480px) {
        .container {
            grid-template-columns: 1fr;
        }
    }
</style>
</head>
<body>
<div class="container">
    <div class="item">Item 1</div>
    <div class="item">Item 2</div>
    <div class="item">Item 3</div>
    <div class="item">Item 4</div>
    <div class="item">Item 5</div>
    <div class="item">Item 6</div>
</div>
</body>
</html>

Output

Item 1
Item 2
Item 3
Item 4
Item 5
Item 6

Responsive Image Example:

Scaling Images Responsively

<!DOCTYPE html>
<html>
<head>
<title>Responsive Image Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
    img {
        max-width: 100%;
        width: 50%; 
        height: 30%;
    }
</style>
</head>
<body>
<img src="{{ url_for('static', filename='B1.jpg') }}" alt="Responsive Image">
</body>
</html>

Output

The image resizes to fit its container while maintaining its aspect ratio:

Responsive Image

Features of Responsive Design: