Sitemap

Member-only story

CSS Media Queries

3 min readSep 12, 2024

--

Press enter or click to view image in full size
CSS Media Queries
CSS Media Queries

For more questions and answers visit our website at Frontend Interview Questions

What are CSS Media Queries?

CSS Media Queries are a technique used to apply styles based on the conditions of the device or viewport. They enable you to create styles that adjust dynamically depending on various factors such as screen size, orientation, resolution, and more. This makes it possible to create responsive layouts that adapt to different devices and user environments.

Syntax

@media mediaType and (condition) {
/* CSS rules */
}
  • @media: The keyword used to define a media query.
  • mediaType: The type of media, such as screen, print, etc. (Optional in modern usage).
  • condition: The condition or feature to evaluate, such as min-width, max-width, orientation, etc.
  • CSS rules: The styles to apply when the condition is met.

Common Media Query Conditions

  1. min-width: Applies styles when the viewport width is at least a specified value.
  2. max-width: Applies styles when the viewport width is no more than a specified value.
  3. orientation: Applies styles based on the device's orientation, such as portrait or landscape.

--

--

Pravin M
Pravin M

Written by Pravin M

I am a frontend developer with 10+ years of experience Blog :- https://www.frontendinterviewquestions.com