
- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursors
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS Advanced
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Media Types
- CSS - Paged Media
- CSS - Aural Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS3 - Rounded Corner
- CSS3 - Border Images
- CSS3 - Multi Background
- CSS3 - Color
- CSS3 - Gradients
- CSS3 - Shadow
- CSS3 - Text
- CSS3 - Web font
- CSS3 - 2d transform
- CSS3 - 3d transform
- CSS3 - Animation
- CSS3 - Multi columns
- CSS3 - User Interface
- CSS3 - Box Sizing
- CSS Responsive
- CSS - Responsive Web Design
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
Responsive Web Design with Media Queries in CSS
Media Queries is a CSS technique for different style rules for different size devices such as mobiles, desktops, etc.
Following is the code showing media queries and responsive web design in CSS −
Example
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; color: white; } @media only screen and (max-width: 600px) { body { background: rgb(207, 60, 151); } } @media only screen and (min-width: 600px) { body { background: rgb(0, 128, 107); } } @media only screen and (min-width: 768px) { body { background: rgb(226, 136, 18); } } @media only screen and (min-width: 992px) { body { background: rgb(108, 25, 185); } } @media only screen and (min-width: 1200px) { body { background: rgb(13, 124, 63); } } </style> </head> <body> <h1>Media queries example</h1> <h2>Resize the screen to see background color change on different breakpoints</h2> </body> </html>
Output
The above code will produce the following output −
- Related Articles
- Create a responsive navigation menu with CSS Media Queries
- CSS3 Responsive Web Design
- Usage of Responsive Web Design
- Responsive web design best for mobile seo strategy
- HTML Viewport meta tag for Responsive Web Design
- Understanding CSS Media Types and Queries
- Media queries with CSS3
- How to use media queries for common device breakpoints with CSS?
- Creating a Responsive Logo with CSS min() Function (No Media Query Involved)
- How to use media queries with JavaScript?
- How to create a printable webpage using CSS media queries?
- Latest CSS Properties and APIs for Web Design in 2020
- How to disable zooming capabilities in responsive design with HTML5?
- Aural Media with CSS
- Set Media Queries for different CSS style rules for different size devices

Advertisements