CSS Media Query Generator
Pick or edit a breakpoint set, choose mobile-first, desktop-first or exact ranges, see which query each device hits and copy the code.
Działa w Twojej przeglądarce. Twoje pliki nigdy nie opuszczają urządzenia. Zobacz, jak to sprawdzić
…
Jak to zrobić
- 1Choose a starting set
Pick a framework such as Bootstrap 5 or Tailwind CSS, or the simple phone, tablet and desktop set.
- 2Edit the breakpoints
Rename, change, add or remove breakpoints; the warnings flag duplicates and breakpoints that are too close together.
- 3Choose the query style
Select mobile first, desktop first or ranges, the classic or range syntax and the unit.
- 4Add conditions
Tick extra features such as hover capability or reduced motion, or switch to container queries.
- 5Test widths
Drag the width slider and read the device table to see which query each screen gets.
- 6Copy the code
Copy the CSS, the SCSS mixins or the matchMedia JavaScript, or download them as files.
O tym narzędziu
Media queries are how a layout changes between a phone, a tablet and a desktop, and most bugs in them come from the edges: a sidebar that appears at 768 pixels in one rule and disappears at 768 in another, a gap of one pixel where no rule applies, or breakpoints copied from a framework you are not using. This generator starts from the breakpoint sets of popular frameworks, Bootstrap 5, Tailwind CSS, Material Design 3, Foundation, Bulma and Chakra UI, or a simple phone, tablet and desktop set, and lets you rename, change, add or remove any breakpoint. Then you choose how the queries are written. Mobile first gives min-width queries that build up from the smallest screen. Desktop first gives max-width queries that step down, using the .02 pixel offset Bootstrap uses so that a max-width rule and the next min-width rule never overlap, even at fractional zoom widths. Ranges give one closed band per breakpoint, which is handy when a style should apply to tablets only. You can write the classic min-width and max-width form or the newer range syntax such as (768px <= width < 992px), which all current browsers support. Units can be pixels, or em and rem, which follow the user's browser font size. Extra conditions such as hover capability, reduced motion, dark mode, high contrast, high-density screens or print can be added to every query.
Which query applies?
Drag the width slider to any viewport width and the tool names the queries that match it. The device table lists common phones, tablets, laptops and desktops in CSS pixels, both portrait and landscape, with the matching query for each. CSS pixels are not hardware pixels: a phone with a screen 1,179 pixels wide reports about 393 CSS pixels because its device pixel ratio is 3, and that is the number media queries see.
Container queries
Turn on container queries to get @container rules instead. They respond to the width of a parent element rather than the whole window, which is ideal for a card that sits in a narrow sidebar on one page and a wide grid on another. Give the container a name if your page has nested containers, and remember to add container-type: inline-size to the parent; the tool reminds you.
Three kinds of output
The CSS tab writes every query with the selector and declarations you type. The SCSS tab writes a $breakpoints map and up, down and between mixins built with sass:map, ready to drop into a partial. The JavaScript tab writes the same queries as strings for window.matchMedia, with a change listener, for menus or charts that need to react in script.
Limits
The tool does not decide your breakpoints for you; good breakpoints come from where your content starts to look wrong, not from device lists. The device sizes are typical values and change with each new model. It does not test your real page; open your site in the browser's responsive mode to confirm the layout.
Przykład z rozwiązaniem
With Bootstrap 5 breakpoints (576, 768, 992, 1200 and 1400) and Ranges in the range syntax, the md band is written as @media (768px <= width < 992px). At a width of 820 pixels, an iPad in portrait, only md matches; in landscape at 1,180 pixels, only lg matches. Switching to desktop first gives @media screen and (max-width: 767.98px) for below-md, and switching the unit to em turns 768px into 48em.
W skrócie
- Kategoria: Programowanie i dane
- Działa w przeglądarce, bez rejestracji i wysyłania.
- Wpisane informacje zostają na Twoim urządzeniu.
- Dostępne po angielsku.
- Treść ostatnio sprawdzona:
- Oficjalne źródło: MDN Web Docs: Using media queries and CSS container queries
Najczęstsze pytania
Mobile first or desktop first?
Mobile first, with min-width queries, is the common choice: the base styles serve phones and each query adds layout for larger screens. Desktop first suits an existing desktop site that needs a few phone fixes. Ranges are best for styles that should apply to one band only.
Why 767.98 instead of 767?
Browsers can report fractional widths at some zoom levels. With max-width: 767px and min-width: 768px, a width of 767.5 pixels matches neither rule. Using 767.98 closes that gap, which is why Bootstrap uses it. The range syntax avoids the problem entirely with width < 768px.
Should I use px or em in media queries?
Em-based queries change with the user's default font size, so someone who sets a larger browser text size gets the narrower layout sooner, which usually reads better. Pixel queries are simpler to reason about. Both are valid; pick one and use it everywhere.
Is the range syntax safe to use?
The Media Queries Level 4 range syntax, such as (width >= 768px), is supported by current Chrome, Edge, Firefox and Safari. If you must support browsers from before 2023, use the classic syntax.
What are container queries for?
They let a component adapt to the space it is given rather than to the window. A product card can show its image beside the text when its container is wide and stack them when it is narrow, wherever the card is placed.
Does it remember my breakpoints?
Yes. Your breakpoints and settings are saved in this browser, with undo and redo, and Save file exports them as JSON.
