Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • HTML Tutorial
  • HTML Exercises
  • HTML Tags
  • HTML Attributes
  • Global Attributes
  • Event Attributes
  • HTML Interview Questions
  • HTML DOM
  • DOM Audio/Video
  • HTML 5
  • HTML Examples
  • Color Picker
  • A to Z Guide
  • HTML Formatter
Open In App
Next Article:
HTML Video
Next article icon

HTML Responsive Web Design

Last Updated : 22 Feb, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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.

responsive-web-design
HTML Responsive Web Design

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

Table of Content

  • 1. HTML Viewport meta tag for Responsive Web Design
  • 2. Responsive Images
  • 3. Responsive Texts
  • 4. CSS media Queries
  • 5. Responsive Layouts

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.


Next Article
HTML Video

J

jatinsharmatu54
Improve
Article Tags :
  • Web Technologies
  • HTML
  • HTML-Questions

Similar Reads

  • HTML Tutorial
    HTML stands for HyperText Markup Language. It is the standard language used to create and structure content on the web. It tells the web browser how to display text, links, images, and other forms of multimedia on a webpage. HTML sets up the basic structure of a website, and then CSS and JavaScript
    10 min read
  • HTML Introduction
    HTML stands for HyperText Markup Language. It is the standard language used to create and structure content on the web. It defines the structure of a webpage by using a series of elements, tags, and attributes to organize text, images, links, and other multimedia elements. HTML is a markup language,
    7 min read
  • HTML Editors
    An HTML Editor is a software application designed to help users create and modify HTML code. It often includes features like syntax highlighting, tag completion, and error detection, which facilitate the coding process. There are two main types of HTML editors: Text-Based Editors - Allow direct codi
    5 min read
  • HTML Basics
    HTML (HyperText Markup Language) is the standard markup language for creating and structuring web pages. It defines the structure of a webpage using elements and tags.HTML is responsible for displaying text, images, and other content.It serves as the foundation for building websites and web applicat
    6 min read
  • HTML Comments
    HTML comments are used to add notes or explanations in the HTML code that are not displayed by the browser. They are useful for documenting the code, making it easier to understand and maintain.To add a comment, use the syntax <!-- your comment here -->. [GFGTABS] HTML <!-- This is a commen
    4 min read
  • HTML Elements
    An HTML Element consists of a start tag, content, and an end tag, which together define the element's structure and functionality. Elements are the basic building blocks of a webpage and can represent different types of content, such as text, links, images, or headings. For example, the <p> el
    5 min read
  • HTML Attributes
    HTML Attributes are special words used within the opening tag of an HTML element. They provide additional information about HTML elements. HTML attributes are used to configure and adjust the element's behavior, appearance, or functionality in a variety of ways. Each attribute has a name and a value
    9 min read
  • HTML Headings
    HTML headings are used to define the titles and subtitles of sections on a webpage. They help organize the content and create a structure that is easy to navigate. Proper use of headings enhances readability by organizing content into clear sections.Search engines utilize headings to understand page
    4 min read
  • HTML Paragraphs
    A paragraph in HTML is simply a block of text enclosed within the <p> tag. The <p> tag helps divide content into manageable, readable sections. It’s the go-to element for wrapping text in a web page that is meant to be displayed as a distinct paragraph. Syntax: <p> Content</p
    5 min read
  • HTML Text Formatting
    HTML text formatting refers to the use of specific HTML tags to modify the appearance and structure of text on a webpage. It allows you to style text in different ways, such as making it bold, italic, underlined, highlighted, or struck-through. Table of Content Categories of HTML Text FormattingLogi
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences