DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk3 min

Media Queries and Pseudo-Classes: How to Make a Website Adapt to Devices and User Actions

Media queries react to the environment; pseudo-classes react to element state. Learn how to combine them, and why hover should never be the only route to content.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Media queries and pseudo-classes solve two different problems. A media query asks about the environment: how wide is the viewport, can the main input device hover, does the user prefer reduced motion? A pseudo-class asks about an element’s state: is it hovered, focused, checked? Use both and a page adapts to the device and to what the visitor is doing. The one rule to keep in mind: hover must never be the only way to reach information or a control.

What a media query does

A media query wraps a set of CSS declarations in a condition. The styles apply only while the condition matches. Width is the most familiar condition in responsive design, but media queries also cover orientation, input capabilities and user preferences (MDN: CSS media queries).

As an Amazon Associate I earn from qualifying purchases.

The syntax combines an optional media type, one or more feature expressions, and logical operators such as and, not and commas for “or” (MDN: Using media queries).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build mobile-first, then add breakpoints

Write base rules that work in a narrow viewport, then add changes where the content needs more room (MDN: Media query fundamentals).

#1 Best Overall
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB | 1920×1080 LED Monitor, 4ms GtG, Adaptive Sync, HDMI 1.4, Tilt Adjust, Low Blue Light, 4yr Advance Replacement Warranty
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
/* Base rules work at narrow widths. */
.card-grid {
  display: grid;
  grid-template-columns: 1fr;
}

/* Add columns when the viewport is wider. */
@media (width >= 40rem) {
  .card-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

The 40rem threshold is an illustration, not a recommended universal breakpoint. Pick breakpoints where your layout starts to look cramped or stretched, not to match particular phone or tablet models.

What a pseudo-class does

A pseudo-class is a colon-prefixed keyword added to a selector. It matches an element only while it is in a certain state or context. Common starter examples are :hover, :active, :focus and :checked (MDN: Pseudo-classes). They let you style these states without JavaScript.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB | 1920×1080 LED Monitor, 4ms GtG, Adaptive Sync, HDMI 1.4, Tilt Adjust, Low Blue Light, 4yr Advance Replacement Warranty
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
.button:hover {
  background: #174ea6;
}

.button:focus-visible {
  outline: 3px solid currentColor;
  outline-offset: 3px;
}

input:checked + label {
  font-weight: 700;
}
  • :hover matches an element a pointer is over.
  • :focus-visible matches a focused element when the browser decides a visible focus indicator should show, typically during keyboard navigation.
  • :checked matches a selected checkbox, radio button or option. Here the adjacent-sibling combinator + styles the label that follows it.

Keep focus styling. If you change the default outline, replace it with something equally visible rather than removing it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Environment versus state at a glance

Question Tool Example
How big is the viewport? Media query @media (width >= 40rem)
Can the primary input hover? Media query @media (hover: hover)
Can any available input hover? Media query @media (any-hover: hover)
Does the user want less motion? Media query @media (prefers-reduced-motion: reduce)
Is this element being hovered right now? Pseudo-class .link:hover
Is this control focused or checked? Pseudo-class :focus-visible, :checked

Combining them: hover styling that respects the device

The two features named “hover” are easy to confuse. :hover matches an element that is currently hovered. @media (hover: hover) tests whether the primary input can conveniently hover, which a mouse usually can and a touchscreen usually cannot (MDN: hover media feature). The any-hover feature asks the same about any available input, not just the primary one.

Rank #3
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.
.link:hover {
  text-decoration-thickness: 0.15em;
}

@media (hover: hover) {
  .link:hover {
    color: rebeccapurple;
  }
}

The media condition checks device capability, not the element’s state, so the nested :hover rule is still needed. MDN’s hover reference reports the feature as widely available across browsers since December 2018, but check the live compatibility tables for the browsers you target.

Making hover effects work on mobile

Touchscreens, keyboards and voice control do not necessarily provide convenient hover. So:

Rank #4
Sale
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor | 100Hz, Game Mode, Advanced Eye Comfort, HDMI and D-sub Ports (LS27D366GANXZA)
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient
  • Don’t hide essential information or actions, such as menus, prices or delete buttons, behind hover alone.
  • Treat hover as an enhancement on top of a visible, working default.
  • Mirror important hover styling with :focus-visible so keyboard users get the same feedback.
  • Use @media (hover: hover) to limit purely decorative hover effects to devices that can hover.
  • Give touch users a tap target, such as a button that toggles content, instead of expecting a hover that never comes.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Adapting to user preferences

User-preference features read system settings. prefers-reduced-motion is a good first one: keep your animation, but tone it down for people who asked for less movement (MDN).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
.card {
  transition: transform 300ms ease;
}

@media (prefers-reduced-motion: reduce) {
  .card {
    transition: none;
  }
}

Support varies by feature, so test in the browsers your audience uses.

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.

A quick checklist

  1. Start with a single-column layout that works at narrow widths.
  2. Add @media (width >= …) rules only where content needs them.
  3. Style states with pseudo-classes, and always include :focus-visible.
  4. Wrap decorative hover effects in @media (hover: hover).
  5. Respect prefers-reduced-motion.
  6. Test with a keyboard (Tab key) and on a real touchscreen or device emulation.

Going further

For a broader reference, O’Reilly lists CSS: The Definitive Guide, 5th Edition by Eric Meyer and Estelle Weyl, which covers media queries and pseudo-class selectors (O’Reilly listing). It’s optional; MDN covers everything above for free.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.