Skip to content
Tutorials Center
My learning

Topics

Lesson 4 of 36 ยท Getting Started

Device Mode and Responsive Testing

Use Device mode to test responsive layouts, touch, pixel ratio and slow networks, and learn its limits, with runnable stand-ins for media queries and pixel density.

Most of your visitors will not use a screen like yours. Device mode lets you see your page as a phone, tablet or small laptop would, without leaving the desk. It changes the viewport size, simulates touch input, sets a device pixel ratio and can add network and CPU throttling.

It is a simulation. It does not run a real phone's browser or hardware, so it is a fast first check and never a replacement for testing on real devices. Knowing what it does and does not model is the difference between a useful test and false confidence.

Turning on Device mode

Click the Toggle device toolbar icon at the top left of DevTools, or press Ctrl+Shift+M (Cmd+Shift+M on macOS). The page area turns into a framed viewport with a toolbar above it.

The toolbar gives you:

  • Dimensions: choose Responsive (any size, drag the handles) or a device preset such as a phone or tablet.
  • Width and height boxes: type exact numbers.
  • Zoom to fit the frame in your window.
  • Throttling list: no throttling, or a CPU slowdown and a network preset.
  • Rotate button: swap width and height to test landscape.
  • More options (three dots): show device frame, show media queries, show rulers, set the device type (mobile or desktop), and Capture screenshot.

The first time you use a device preset, Chrome also changes the User-Agent string and the device type, so servers that sniff the user agent may send you a mobile page.

Media query bars and breakpoints

Turn on Show media queries from the three-dot menu. A colored bar appears above the viewport for each @media rule in the page's CSS: blue bars for max-width queries, green for ranges, orange for min-width. Clicking a bar resizes the viewport to that breakpoint, which is a quick way to see exactly where your layout changes.

If a layout looks right at the preset sizes but breaks at 700 pixels, drag the Responsive handle slowly and watch where it fails. Breakpoints are most useful when chosen where your content breaks, not at device sizes.

What the viewport actually is

On a phone, the browser uses a layout viewport and a visual viewport. Two page ingredients make mobile layouts behave:

  • <meta name="viewport" content="width=device-width, initial-scale=1"> in the HTML head. Without it, a mobile browser pretends the screen is about 980 CSS pixels wide and shrinks the page, and Device mode in Mobile type will reproduce that shrunken look.
  • CSS pixels versus device pixels: a phone may have a screen 1170 device pixels wide that reports a width of 390 CSS pixels. The ratio is the device pixel ratio (DPR), here 3. Images need to be sharp at that density; layout is written in CSS pixels.

In Device mode you can set the DPR in the toolbar's More options when the device pixel ratio field is shown. The page reads it as window.devicePixelRatio.

Stand-in: does a media query match?

The browser decides which @media rules apply by comparing the viewport with each condition. Here is a tiny evaluator for min-width and max-width. It is a model of the idea, not Chrome's parser.

JS Stand-in: which breakpoints match?

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Notice that exactly one query matches each width here, because the ranges do not overlap. Overlapping ranges are a common cause of "why do these two rules fight?" bugs, and Device mode's colored bars help you spot them.

Stand-in: pixel density and image size

Retina and high-density screens need more pixels in an image to look sharp. This calculator shows how many image pixels a slot needs for a given DPR. Use it to reason about srcset widths; it is a stand-in for the arithmetic, not a DevTools feature.

JS Stand-in: image pixels for a slot

Press Run (or Ctrl + Enter) to see the console output here.

No output.

When you inspect an <img> with a srcset in the Elements panel, hovering the image shows its rendered size and its intrinsic size, which tells you the same story.

Throttling and touch in Device mode

The Throttling dropdown on the device toolbar applies a network profile and a CPU slowdown together to simulate a weaker phone. It is described more fully in the Network lessons; the key point here is that desktop CPUs are fast, and a page that is smooth on your laptop can stutter on a mid-range phone. Use a CPU slowdown such as 4x as a rough guide.

Touch simulation turns the cursor into a circle and sends touch events, so handlers like touchstart fire. Hover styles do not exist on real phones, so test layouts that rely on :hover menus carefully.

What Device mode cannot show you

  • Real mobile browser quirks (Safari on iPhone has its own engine, so some CSS and scrolling behavior differs).
  • Real memory, battery and GPU limits.
  • Bottom browser bars that appear and disappear and resize the viewport.
  • Real keyboards pushing content up when a field is focused.

For those, connect a phone with USB debugging and use Remote devices at chrome://inspect, or use a device cloud. Treat Device mode as the first filter.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which shortcut toggles the device toolbar on Windows?

    Ctrl+Shift+M toggles Device mode; Ctrl+Shift+D cycles dock side.
  2. 2. A phone screen is 1170 device pixels wide and reports 390 CSS pixels. What is its device pixel ratio?

    1170 divided by 390 equals 3.
  3. 3. Why might a mobile layout render as a tiny shrunken desktop page?

    Without width=device-width, mobile browsers assume a wide virtual viewport (about 980 CSS pixels) and scale the page down.
  4. 4. Which problem is Device mode least able to reproduce?

    Device mode simulates inside Chrome's engine, so another browser engine's quirks need real device testing.

Summary

  • Device mode (Ctrl+Shift+M) simulates viewport size, touch, user agent, pixel ratio and throttling.
  • Show media queries to jump between breakpoints; set breakpoints where content breaks.
  • Always include the viewport meta tag, and think in CSS pixels versus device pixels.
  • It is a simulation: confirm on real devices for engine, hardware and browser-UI differences.

Next: The Elements Panel and the DOM Tree