How to make a HTML div responsive using CSS ? Last Updated : 23 Jul, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 @media rule consists of a media type and it can have one or more expressions, which can result in values like "true" or "false".The following meta viewport element has to be included in the "head" section of the HTML file for the responsive web page. <meta name=”viewport” content=”width=device-width, initial-scale=1.0”> Syntax:@media not|only mediatype and (expressions) { // Your CSS codes}Approaches:First create a HTML structure with three div for creating box like structure and add heading with help of heading tagNow set a default font size for all elements and establish a base structure for the responsive divs with a fixed height and width.Organize three divs within a container div, each with a specific width, inline-block display, and distinct background colors.Implement a media query to adjust div widths to 70% when the screen width is 500px or less, ensuring responsiveness on smaller devices.Example: HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Responsive Blocks</title> <style> body { font-family: Arial, sans-serif; text-align: center; margin: 0; padding: 0; background-color: #f4f4f4; } h1 { margin-top: 20px; color: #333; } p { color: #555; } .mnb { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin: 20px 0; } .mnb div { height: 100px; width: 200px; display: flex; align-items: center; justify-content: center; color: white; font-weight: bold; border-radius: 5px; } .first { background-color: green; } .second { background-color: blue; } .third { background-color: yellow; color: black; } @media screen and (max-width: 500px) { .mnb div { width: 70%; font-size: 20px; } } </style> </head> <body> <h1>Geeks for Geeks</h1> <p>Responsive div using CSS.</p> <div class="mnb"> <div class="first"> <p>First block</p> </div> <div class="second"> <p>Second block</p> </div> <div class="third"> <p>Third block</p> </div> </div> <p> The media query will only apply if the media type is screen and the viewport is equal to or less than 500px </p> </body> </html> Output:Similarly, one can add or change various styles for a particular HTML element for different screen sizes by adding CSS code in @media query section as shown in the above example. Comment More infoAdvertise with us Next Article How to create a Responsive Inline Form using CSS ? D deepak710agarwal Follow Improve Article Tags : Web Technologies CSS CSS-Questions Similar Reads How to Create a Responsive Image Grid using CSS? A responsive image grid is a layout technique used to display images in a grid-like structure that adjusts dynamically based on the screen size to ensure that the grid looks good and functions well across various devices and screen resolutions. Below are the approaches to creat a responsive image gr 3 min read How to Create Responsive Sidebar using HTML & CSS ? Creating a responsive sidebar using HTML and CSS means designing a navigation menu that adapts seamlessly to different screen sizes. It provides a user-friendly experience on both desktop and mobile devices, adjusting its layout for better readability and easy access to content. PreviewApproachBasic 2 min read How to create Responsive iFrames using CSS ? An iframe, or inline frame, is an HTML element used to embed another document or webpage within the current document. Responsive iframes can be achieved by defining the aspect ratio, which refers to the proportional relationship between the width and height of an element. To maintain the aspect rati 4 min read How to create a Responsive Inline Form using CSS ? When the browser window is resized, the labels and inputs will stack on top of each other for smaller screens. To create a responsive inline form using CSS, use a container with flexible styling, such as Flexbox or Grid, to arrange form elements horizontally. Utilize media queries to adjust the layo 3 min read How to Create a Responsive Image Gallery using CSS? Creating a responsive image gallery using CSS is a common task in web development. A responsive gallery adjusts to different screen sizes and ensures that images look good on devices ranging from mobile phones to desktop monitors. In this article, we will explore different approaches to creating a r 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 u 2 min read Like