The Wayback Machine - https://web.archive.org/web/20240819233553/https://www.geeksforgeeks.org/html-responsive-web-design/
Open In App

HTML Responsive Web Design

Last Updated : 30 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

HTML Responsive Web Design is a modern approach to web development that ensures web pages look great on any device, from phones and tablets to desktop computers. It focuses on making HTML elements automatically adjust—resizing, hiding, or repositioning based on the screen size. This approach guarantees a seamless and visually appealing user experience across various devices.

In this article, we’ll explore practical examples and techniques for creating HTML responsive web designs that adapt perfectly to different screen sizes, ensuring optimal functionality.

What is Responsive Web Design?

Responsive Web Design is an approach to web development that ensures web pages render well on a variety of devices and window or screen sizes. It involves using fluid grids, flexible images, and CSS media queries to adapt the layout of a website dynamically based on the screen size, orientation, and resolution of the device being used.

This technique allows websites to provide an optimal viewing experience, easy reading, and navigation with minimal resizing, panning, and scrolling across different devices, from desktop monitors to mobile phones.

Examples of HTML Responsive Web Design

1. HTML Viewport meta tag for Responsive Web Design

The HTML viewport is the visible area of the screen that users see. It changes depending on the device being used. With this approach, we set the width of web pages to match the available screen width, making it 100%. This helps content adapt and look good on any device, ensuring a responsive layout.

Syntax

<meta name="viewport" content= "width=device-width, initial-scale=1.0">

Example: Use of the HTML viewport meta tag for responsive pages.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>GeeksforGeeks</title>
    <meta charset="utf-8"
          name="viewport"
          content="width=device-width,
                   initial-scale=1.0" />
    <style>
        .gfg {
            font-size: 40px;
            font-weight: bold;
            color: green;
            text-align: center;
        }

        .geeks {
            font-size: 17px;
            text-align: center;
        }

        p {
            text-align: justify;
        }
    </style>
</head>

<body>
    <div class="gfg">GeeksforGeeks</div>
    <div class="geeks">HTML Introduction</div>

    <p>
        HTML stands for HyperText Markup Language. It is
        used to design web pages using a markup
        language. HTML is a combination of Hypertext and
        Markup language. Hypertext defines the link
        between web pages. A markup language is used to
        define the text document within the tag which
        defines the structure of web pages. This
        language is used to annotate (make notes for the
        computer) text so that a machine can understand
        it and manipulate text accordingly. Most markup
        languages (e.g. HTML) are human-readable. The
        language uses tags to define what manipulation
        has to be done on the text.
    </p>
</body>

</html>

Output


2. Responsive Images

Responsive images play a key role in responsive websites. These are images that can adjust their size, getting bigger or smaller, based on the width of the browser. By being responsive, images enhance user experience across different devices with varying screen sizes. The following are the techniques to use the responsive images:

2.1 Using width Property

The image can be responsive & scale up & down with the help of CSS width property by setting its value as 100%.

Syntax

<img src="..." style="width:100%;">

Example: In this example, we will use the image width property to occupy 100% of the screen width.

HTML
<!DOCTYPE html>
<html>

<head>
    <meta name="viewport" content=
        "width=device-width, initial-scale=1.0" />
</head>

<body>
    <img class=".img-fluid" src=
"https://media.geeksforgeeks.org/wp-content/uploads/20220201191443/logo-200x32.png"
         style="width: 100%" />

    <h2>Responsive Images</h2>
  
    <p>
        Responsive images are just a part of Responsive
        websites. Images that can change their
        dimensions, scaling them up or down, according
        to the browser width are responsive images. The
        above image is responsive as it is adjusting
        itself according to the width of the browser.
    </p>
</body>

</html>

Output

2.2 Using the max-width Property

The max-width property sets the maximum width of an element. It restricts the element’s width from exceeding a certain value. If the content is larger than this maximum width, it wraps to the next line. However, if the content is smaller, the property has no impact. Also, if the content is larger than its original size, it won’t scale up beyond the specified max-width.

Syntax:

<img src="..." style="max-width:100%; height:auto;">

Example: Implementation of the max-width Property for making the Responsive Images

HTML
<!DOCTYPE html>
<html>

<head>
    <meta name="viewport" 
          content="width=device-width,
                   initial-scale=1.0" />
</head>

<body>
    <img class=".img-fluid"
         src=
"https://media.geeksforgeeks.org/wp-content/uploads/20220201191443/logo-200x32.png"
         style="max-width:100%;
                height:auto;" />
    <h2>Responsive Images</h2>
    <p>
        Responsive images are just a part of Responsive
        websites. Images that can change their
        dimensions, scaling them up or down, according
        to the browser width are responsive images. The
        above image is responsive as it is adjusting
        itself according to the width of the browser.
    </p>
</body>

</html>

Output

2.3 Responsive Image for different Browser Width

To make images responsive, HTML provides the <picture> element. It gives web developers the flexibility to specify different image resources depending on the size of the browser window

Example

HTML
<!DOCTYPE html>
<html>

<head>
    <title>HTML Responsive Web Design</title>
</head>

<body style="text-align: center;">
    <h1 style="color: green;">GeeksforGeeks</h1>

    <h2>HTML picture Tag</h2>

    <picture>
        <source media="(min-width: 700px)"
                srcset=
"https://media.geeksforgeeks.org/wp-content/uploads/20190825000042/geeks-221.png">

        <source media="(min-width: 450px)"
                srcset=
"https://media.geeksforgeeks.org/wp-content/uploads/20190802021607/geeks14.png">

        <img src=
"https://media.geeksforgeeks.org/wp-content/uploads/20190808102629/geeks15.png"
             alt="GFG">
    </picture>
</body>

</html>

Output

3. Responsive Texts

In this method, we set font sizes using %, vw, vh, etc. This ensures that text sizes are responsive, adjusting automatically until reaching a certain limit. Once the limit is reached, the content is justified to fit within the available width.

Example: This example demonstrates Responsive Web Design by making Responsive Texts.

HTML
<!DOCTYPE html>
<html>

<head>
    <style>
        body {
            max-width: 100%;
        }

        .gfg {
            font-size: 7vw;
            font-weight: bold;
            color: green;
            text-align: center;
        }

        .geeks {
            font-size: 5vw;
            text-align: center;
        }

        p {
            font-size: 3vw;
            text-align: justify;
        }
    </style>
</head>

<body>
    <div class="gfg">GeeksforGeeks</div>
    <div class="geeks">HTML Introduction</div>

    <p>
        HTML stands for HyperText Markup Language. It is
        used to design web pages using a markup
        language. HTML is a combination of Hypertext and
        Markup language. Hypertext defines the link
        between web pages. A markup language is used to
        define the text document within the tag which
        defines the structure of web pages. This
        language is used to annotate (make notes for the
        computer) text so that a machine can understand
        it and manipulate text accordingly. Most markup
        languages (e.g. HTML) are human-readable. The
        language uses tags to define what manipulation
        has to be done on the text.
    </p>
</body>

</html>

Output:

4. CSS media Queries

The Media query in CSS is essential for crafting responsive web designs. It ensures that web pages adapt to various screen sizes and device types. Breakpoints are set to define when the content starts to adjust or change layout based on the device’s width.

Media queries can be used to check many things:

  • width and height of the viewport
  • width and height of the device
  • Orientation
  • Resolution

Syntax

@media not | only mediatype and (expression) {
// Code content
}

Example: In this example, we will use screen size in a media query to make the webpage responsive according to different breakpoints.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>GeeksforGeeks</title>
    <style>
        .gfg {
            font-size: 100px;
            font-weight: bold;
            color: green;
            text-align: center;
        }
        
        .geeks {
            font-size: 50px;
            text-align: center;
        }
        
        p {
            font-size: 25px;
            text-align: justify;
        }
        
        /* styling for screen width less than 800 */
        @media screen and (max-width: 800px) {
            body {
                background-color: aqua;
            }
        
            .gfg {
                font-size: 50px;
            }
        
            .geeks {
                font-size: 25px;
            }
        
            p {
                font-size: 12px;
            }
        }
    </style>
</head>

<body>
    <div class="gfg">GeeksforGeeks</div>
    <div class="geeks">HTML Introduction</div>

    <p>
        HTML stands for HyperText Markup Language. It is
        used to design web pages using a markup
        language. HTML is a combination of Hypertext and
        Markup language. Hypertext defines the link
        between web pages. A markup language is used to
        define the text document within the tag which
        defines the structure of web pages. This
        language is used to annotate (make notes for the
        computer) text so that a machine can understand
        it and manipulate text accordingly. Most markup
        languages (e.g. HTML) are human-readable. The
        language uses tags to define what manipulation
        has to be done on the text.
    </p>
</body>

</html>

Output: Background color and font size transition for width less than 800px.

Note: Sometimes, this method doesn’t show the correct output on Google Chrome.

5. Responsive Layouts

The responsive layout module of CSS includes the following properties.

5.1 Using flexbox property

In this approach, we will use CSS display property to make the page responsive. Display layouts like flexbox, inline, blocks, and grids can be used to make the design responsive. CSS flexbox property auto adjusts the content (no. of columns in a row) according to the screen width as shown in the output gif.

Syntax

.container{
display: flexbox;
}

Example: In this example, we will use display type flexbox to show adjust items automatically according to the screen size.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>GeeksforGeeks</title>
    <style>
        body {
            background-color: aqua;
        }
        .gfg {
            font-size: 5vw;
            font-weight: bold;
            color: green;
            text-align: center;
        }
        button {
            width: 300px;
            font-size: larger;
        }
        .container {
            display: flexbox;
        }
    </style>
</head>

<body>
    <div class="gfg">GeeksforGeeks</div>
    <div class="container">
        <button>HTML</button>
        <button>CSS</button>
        <button>JavaScript</button>
    </div>
</body>

</html>

Output

Note: Sometimes, this method doesn’t show the correct output on Google Chrome.

5.2 Using CSS Grids

This approach uses a CSS display grid to create a 2D layout along with other grid options. It allows us to decide the number of columns we want to keep and instead of rearranging the columns like Flexbox, it adjusts the content within individual column elements.

Syntax

.container{
display: grid;
/* To define colums*/
grid-template-columns: 1fr 1fr;
}

Example: In this example, CSS Grid layout is used to arrange contents in 2D form, i.e., rows and columns.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>GeeksforGeeks</title>
    <style>
        body {
            background-color: aqua;
        }
        .gfg {
            font-size: 5vw;
            font-weight: bold;
            color: green;
            text-align: center;
        }
        
        .container {
            font-size: x-large;
            text-align: center;
            display: grid;
            grid-template-columns: 1fr 1fr;
        }
        .grid-item {
            background-color: rgb(220, 208, 232);
            border: 2px solid rgb(70, 54, 84);
        }
    </style>
</head>

<body>
    <div class="gfg">GeeksforGeeks</div>
    <div class="container">
        <div class="grid-item">HTML</div>
        <div class="grid-item">CSS</div>
        <div class="grid-item">JavaScript</div>
        <div class="grid-item">Bootstrap</div>
    </div>
</body>

</html>

Output

Note: Sometimes, this method doesn’t show the correct output on Google Chrome.

5.3 Using CSS MultiColumn

It is similar to grids. CSS MulotiColumn allows developers to choose the properties like no. of columns, width, gap, etc. for each column. These values remain unchanged but the content inside the columns adjusts.

Syntax

.container{
column-count: 3; /* Number of columns*/
column-gap: 20px; /* Gap between columns*/
column-width: 200px; /* Width of each column*/
/* Other column properties*/
}

Example: This example uses CSS MultiColumn for content division into a specific number of columns.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>GeeksforGeeks</title>
    <style>
        body {
            background-color: aqua;
        }
        .gfg {
            font-size: 5vw;
            font-weight: bold;
            color: green;
            text-align: center;
        }
        
        .container {
            font-size: x-large;
            text-align: left;
            column-count: 3;
            column-gap: 5%;
        }
    </style>
</head>

<body>
    <div class="gfg">GeeksforGeeks</div>
    <div class="container">
        <div>
            HTML stands for HyperText Markup Language.
            It is used to design web pages using a
            markup language. HTML is a combination of
            Hypertext and Markup language. Hypertext
            defines the link between web pages. A markup
            language is used to define the text document
            within the tag which defines the structure
            of web pages. This language is used to
            annotate (make notes for the computer) text
            so that a machine can understand it and
            manipulate text accordingly. Most markup
            languages (e.g. HTML) are human-readable.
            The language uses tags to define what
            manipulation has to be done on the text.
        </div>
    </div>
</body>

</html>

Output


HTML Responsive Web Design allows websites to adapt to various screen sizes, ensuring a seamless user experience across devices. By using HTML and responsive techniques, designers and developers can create websites that look great whether viewed on a desktop or a smartphone.

This flexibility enhances accessibility and usability, making browsing a breeze for all users. In essence, HTML Responsive Web Design is important for ensuring that websites remain functional and visually appealing regardless of the device being used.

HTML Responsive Web Design – FAQs

Why is Responsive Web Design important?

Responsive design ensures a consistent and optimal viewing experience across different devices, improving accessibility, user experience, and engagement.

How does a viewport meta tag help in Responsive Web Design?

It sets the width of web pages to match the device’s screen width, ensuring content adapts to different screen sizes.

What are some common layout techniques for responsive design?

Common techniques include using CSS Flexbox, CSS Grid, and MultiColumn layouts to adjust the content dynamically based on the screen size.

Can Responsive Web Design improve SEO?

Yes, it can improve SEO by providing a better user experience, reducing bounce rates, and ensuring that the site is accessible and usable across various devices, which search engines favor.

What is the difference between adaptive and responsive web design?

Adaptive web design uses multiple fixed layouts for different screen sizes, while responsive web design uses a single flexible layout that adjusts dynamically to the screen size.



Previous Article
Next Article

Similar Reads

HTML Viewport meta tag for Responsive Web Design
A Browser's viewport is the area of the web page in which the content is visible to the user. The viewport does not have the same size, it varies with the variation in screen size of the devices on which the website is visible. For a laptop, the viewport has a larger size as compared to a smartphone or tablet. Note: When a page is not made responsi
3 min read
How to design a responsive Web Page in HTML ?
In this article, we will learn how to design a responsive Web Page in HTML. Responsive web design (RWD) is a web development approach that creates dynamic changes to the appearance of a website, depending on the screen size and orientation of the device being used to view it. RWD can be obtained by using HTML and CSS to automatically resize, hide,
3 min read
Short note on Responsive Web Design
Responsive Web Design comprises two words i.e., responsive and web design. Responsive means to respond and web design means to design website. Therefore, responsive web design generally means website that respond to or resize or adjust itself depending upon screen size it is being seen through. It automatically adjusts to fit user’s screen whether
3 min read
Advantages and Disadvantages of Responsive Web Design
Today's generation is living in a world where everything is changing quickly, technologies are improving and changing day by day, businesses are expanding and growing widely. People usually try their best to expand, maintain, improve size, popularity, increase the value of the brand, and bring ahead their business from other competitors. The websit
4 min read
Tools for Responsive Web Design
Responsive websites are essential nowadays for the growth of the business. These are websites created to ensure that website looks good on all devices such as desktop, laptop, smartphone, tablet, etc. It will usually contain the same content, images, and other elements on every device it is viewed on, only changes that occur in the size and way pag
4 min read
What is a Breakpoint in Responsive Web Design?
To create websites that look great on any device, whether it's a desktop computer, tablet, or smartphone. That's where responsive design comes in. It's a technique that ensures your website adapts to different screen sizes and provides an optimal user experience. One of the key elements of responsive design is breakpoints, which are pivotal points
6 min read
Basics of Responsive Web Design - Media Queries
Media queries in CSS are essential for creating responsive designs that adapt to different device sizes and orientations. They allow developers to apply styles based on various conditions, ensuring optimal display across different devices. What are Media Queries?Media queries enable conditional styling based on factors such as viewport dimensions,
2 min read
Features of Responsive Web Design
Website is more essential for growth of company or business. It is the best way to reach more audience. Nowadays, each and every user and clients use mobiles phones more than anything and therefore wants a mobile version of website. But it's difficult and sometime impossible to create website versions for each new resolutions and devices. That's wh
3 min read
What is RWD(Responsive Web Design) ?
In this article, we will learn about Responsive Web Design(RWD). It is the most important approach in web development which creates dynamic changes to the appearance of a website, depending on the screen size and orientation of the device being used to view it. A website that is responsive in nature looks good on every device. What are the language
4 min read
Difference between responsive design and adaptive design
In this article, we will discuss the difference between responsive design and adaptive design. Both are the designing part of a website but how both of them are different from each other. In earlier times, web designers design the user interface of the website by considering the size of the desktop. but nowadays we use websites for Mobile, Tablet,
4 min read
Design a Responsive Services Section Template using HTML and CSS
A Services Website plays a vital role in showcasing the different services that a particular company or any other contractor has to offer. In this article, we are going to build a services page, it will illustrate the different components of the services like the title, description, and learn more button. We will use HTML to define the basic struct
4 min read
Design Responsive Flower Store in HTML CSS & JavaScript
In this article, we will see how can we design a Responsive Flower Store with the help of HTML, CSS, and JavaScript. Prerequisites:HTMLCSSJAVASCRIPT Approach:Created a login form using basic html CSS Created Signup form .Created a Sign out Cart page on the main page first Created a navbar with home shop about us cart contact signin login section.af
15+ min read
Design a Responsive Sliding Login & Registration Form using HTML CSS & JavaScript
In this article, we will see how to create the Responsive Sliding Login &amp; Registration Form using HTML CSS &amp; JavaScript, along with understanding its implementation through the illustration. Many websites, nowadays, implement sliding login &amp; registration forms for their sites. A Registration form is used to register or create a new acco
5 min read
How to Make Responsive Vertical Timeline Design using only HTML and CSS ?
A Timeline is a list of events according to the order of dates which is used to get an overview of various tasks and their expected timing. Crafting a responsive vertical timeline design using only HTML and CSS involves making a visually pleasing layout that arranges content chronologically in a vertical manner. To make it responsive for small devi
5 min read
Design a Responsive Product Card using HTML, CSS & JavaScript
We'll create a responsive product card using HTML, CSS, and JavaScript. A product card is a basic UI element used in e-commerce websites to show product details in a simple format. We're creating a one-size-fits-all product card for online use. It's designed to work well on any screen size so it will be fully responsive. Output preview: Prerequisit
4 min read
Difference Between Web 1.0, Web 2.0, and Web 3.0
Web 1.0 was all about fetching, and reading information. Web 2.0 is all about reading, writing, creating, and interacting with the end user. It was famously called the participative social web. Web 3.0 is the third generation of the World Wide Web, and is a vision of a decentralized web which is currently a work in progress. It is all about reading
8 min read
How to Create Good Responsive Design?
First, one should know what exactly responsive design means. In simple words, responsive design is a way that simply allows website design and code to adjust itself or respond according to the size of the device’s screen. The main goal of responsive design is to increase positive user experience across all types of devices such as desktop, laptop,
5 min read
What to understand Pure CSS Responsive Design ?
In this article, we will learn about Pure.CSS responsive design. It is a collection of responsive CSS modules that can be included in any web application to create faster, beautiful, and responsive websites. In simple words, it is a framework of CSS that is used to build a beautiful and responsive website in less time. Pure CSS is a CSS framework t
3 min read
Design a Responsive Dropdown Menu in Tailwind CSS
Dropdown menus play a crucial role in web design, providing users with a convenient way to access additional options or navigate through a website's content hierarchy. ApproachThe HTML structure and CSS classes used in this code are designed to create a responsive dropdown menu. Tailwind CSS provides utility classes for responsive design, allowing
3 min read
How to design Responsive card-deck with fixed width in Bootstrap?
To design a responsive card deck with a fixed width in Bootstrap, utilize a grid layout of cards. Apply custom CSS to set a fixed width for each card, ensuring they maintain consistent dimensions across various screen sizes. Utilize Bootstrap's responsive utilities to adjust card spacing and layout as needed for different viewport sizes. ApproachBe
3 min read
Design a Responsive Card with a Carousel inside it in Bootstrap
A responsive carousel displays images or content in a rotating manner, adjusting seamlessly to different screen sizes for optimal viewing experience. In this article, we will create a responsive card with a carousel inside it with the help of Bootstrap5. Preview:[video loading="lazy" mp4="https://media.geeksforgeeks.org/wp-content/uploads/202407212
2 min read
10 Web Development and Web Design Facts That You Should Know
Web Development has grabbed a lot of attention in today's date. But the question arises, why has it gained such a massive audience in the last decade. So Here's the answer: Web development is the basic building and maintenance of websites; it’s the whole procedure that happens to make a website look great, responsive, work smooth, and performing we
6 min read
How to create Responsive Profile Card using HTML and CSS ?
In this article, we are going to create a profile card from where a user can check out the basic details of other users and connect with them through different handles as well as message the user. Approach:Set up HTML with a container div containing an image and content sections.Style the container, user image, and content sections with appropriate
5 min read
HTML Responsive Modal Login Form
In this article we will create a responsive modal login form in HTML by utilizing a combination of HTML, CSS, and JavaScript. Design the modal to overlay the page, adjusting its size and layout to fit various screen sizes. Incorporate form elements for username and password entry, with validation if required, and add a close button for user conveni
4 min read
How to Create Responsive Sidebar using HTML & CSS ?
We will create a responsive sidebar which is created using HTML and CSS. The responsive sidebar will be interactive for small devices also. ApproachCreate HTML and CSS files. After getting the boiler plate code title has been changed as Responsive sidebar.CSS File has been linked to HTML using link tag within head tag.Create a div with the class na
2 min read
How to put a responsive clear button inside HTML input text field ?
To embed a responsive clear button within an HTML input text field, you create both elements within a shared container. Using CSS, position the button within the input field, typically at the right end. JavaScript or jQuery can enable functionality to clear the input's content upon button click. Creating structure: In this section, we will create t
3 min read
Create a Responsive Admin Dashboard using HTML CSS and JavaScript
In this article, we will see how to create the Responsive Admin Dashboard using HTML, CSS &amp; JavaScript, along with understanding its implementation through the illustration. This project involves structuring the HTML layout for navigation, sidebar, and content, styling with CSS to ensure responsiveness, incorporating interactive elements using
10 min read
How to make a HTML div responsive using CSS ?
The CSS Media Query can be used to make an HTML "div" responsive. The media queries allow the users to change or customize the web pages for many devices like desktops, mobile phones, tablets, etc without changing the markups. Using the media query, the user can change the style of a particular element for different sizes of screen. Note: The CSS @
2 min read
Creating Responsive Grid Vanilla using HTML,CSS and Bootstrap
Many modern websites use a grid system to display chunks of data on their home-page as well as other pages. To much extent grid resembles a table, however, it is much more visually appealing and most often displays sibling elements. A grid must be responsive, i.e. it should adjust to the screen size of the user. Bootstrap is a very popular open-sou
5 min read
Responsive analog clock using HTML, CSS and Vanilla JavaScript
In this article, we are going to create an Analog Clock. This is mainly based on HTML, CSS &amp; Vanilla JavaScript. Approach: Create an HTML file in which we are going to add the main div, further on we are adding 4 div tags for an hour, minute, and second hands &amp; for the pin.Create a CSS file for styling our web page and for assigning differe
4 min read
three90RightbarBannerImg