CSS grid Media Feature

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The grid media feature tests whether the output device uses a grid-based screen (for example a text terminal) instead of a typical bitmap screen.

Most phones and monitors are bitmap devices and match grid: 0. Grid-based examples include text-only terminals and basic phones with one fixed font. This is not a test for CSS Grid layout (display: grid / grid).

Baseline · Widely available.

Not deprecated. Parsed widely; on modern bitmap screens you almost always get grid: 0.

Warning Not CSS Grid detection

To feature-detect CSS Grid layout, use @supports (display: grid). Do not use @media (grid) for that.

CSS Syntax

syntax.css
@media (grid: 0 | 1) { … }

Boolean form: @media (grid) { … } matches when the value is 1 (grid-based). Always wrap the feature in parentheses.

Feature Values

ValueDescriptionTry it
0Not grid-based (typical bitmap screens)Try it
1Grid-based output (terminals, some basic phones)Try it
(grid)Boolean form — true when value is 1Try it
Both labelsShow different messages for bitmap vs grid devicesTry it

How to Use grid

Keep bitmap-friendly defaults, then optionally adapt for rare grid devices.

  1. Write normal styles that work on bitmap screens (almost every modern device).
  2. Optional: use @media (grid: 0) for bitmap-only emphasis.
  3. Optional: use @media (grid: 1) or @media (grid) for terminal-style tweaks (simpler type, fewer effects).
  4. Never use this query to decide whether to apply display: grid.
PieceRequired?Role
@mediaYesWraps the media feature
0 or 1Yes*Bitmap vs grid-based (*or use boolean (grid))
Default stylesYesMust work when the query does not match

Live Preview

This device’s grid value via matchMedia. On a normal monitor or phone you should see grid: 0.

Detected grid queries

Bitmap devices match (grid: 0). Grid terminals match (grid: 1) / boolean (grid).

Device check
(grid: 0) (grid: 1) (grid)

Checking…

Checking…

CSS Examples

Each snippet focuses on the grid media feature (device type), not CSS Grid layout. Use Try It Yourself for a live editor.

Example 1 — Styles for Bitmap Screens

Emphasize a message when the device is not grid-based.

CSS
<style>
  .bitmap {
    color: #64748b;
  }

  @media (grid: 0) {
    .bitmap {
      color: #dc2626;
      text-transform: uppercase;
    }
  }
</style>

<p class="bitmap">You are using a bitmap device.</p>
Try It Yourself

How It Works

  1. Set a calm default. Gray text works everywhere.
  2. Query bitmap. @media (grid: 0) matches typical screens.
  3. Emphasize the label. Color and uppercase apply only on bitmap devices.
  4. Common case. On your laptop or phone this query usually matches.

Example 2 — Styles for Grid Devices

Highlight a message only on grid-based output.

CSS
<style>
  .grid-device {
    color: #64748b;
  }

  @media (grid: 1) {
    .grid-device {
      color: #0f172a;
      text-transform: uppercase;
    }
  }
</style>

<p class="grid-device">You are using a grid device!</p>
Try It Yourself

How It Works

  1. Quiet default. The paragraph stays muted on bitmap screens.
  2. Query grid devices. @media (grid: 1) matches terminals and similar hardware.
  3. Stronger text. Dark color and uppercase appear only then.
  4. Boolean option. @media (grid) means the same as (grid: 1).

Example 3 — Show the Matching Label

Mute both labels by default; reveal the one that matches.

CSS
<style>
  .bitmap,
  .grid-device {
    color: #cbd5e1;
  }

  @media (grid: 0) {
    .bitmap {
      color: #dc2626;
      text-transform: uppercase;
    }
  }

  @media (grid: 1) {
    .grid-device {
      color: #0f172a;
      text-transform: uppercase;
    }
  }
</style>

<p class="bitmap">You are using a bitmap device.</p>
<p class="grid-device">You are using a grid device!</p>
Try It Yourself

How It Works

  1. Mute both. Light gray makes inactive labels fade back.
  2. Bitmap branch. (grid: 0) highlights the bitmap line.
  3. Grid branch. (grid: 1) highlights the grid-device line.
  4. Study aid. Same pattern as MDN’s basic demo for comparing device types.

Edge Cases & Pitfalls

Name collisions and rare hardware cause most confusion.

naming

Not CSS Grid layout

@media (grid) ≠ grid / display: grid. Use @supports (display: grid) for layout support.

rarity

grid: 1 is uncommon

Modern consumer devices are bitmap. Treat grid-device styles as progressive enhancement for niche hardware.

boolean

(grid) means “is 1”

Boolean @media (grid) matches grid-based devices only. Bitmap screens need (grid: 0).

defaults

Keep usable defaults

Do not hide critical UI inside (grid: 1) only. Most users will never hit that branch.

related

Pair with other device queries

For terminals and specialty screens, also consider monochrome, color, and scan.

Browser Support

grid is a browser media feature for device screen type. Node.js, Deno, and Bun do not evaluate it.

✓ Baseline · Widely available

grid

Widely available across modern browsers for many years. On everyday bitmap hardware the matched value is almost always 0.

97% Global support
Google Chrome 29+
Full support
Mozilla Firefox 8+
Full support
Apple Safari 6+
Full support
Microsoft Edge 12+
Full support
Opera 16+
Full support
Samsung Internet 2+
Full support
Internet Explorer 10+
Full support
@media (grid) Widely supported

Bottom line: Safe to parse everywhere. Expect grid: 0 on phones and PCs. It is not a JavaScript runtime API and not a CSS Grid layout detector.

Key Takeaways

  • Role: detect grid-based vs bitmap output devices.
  • Values: 0 (bitmap) and 1 (grid-based).
  • Not layout Grid. Use @supports (display: grid) for CSS Grid.
  • Practice: defaults for bitmap; optional tweaks for grid: 1.

One line: @media (grid: 0|1) asks about the screen type, not whether CSS Grid layout works.

Frequently Asked Questions

It tests whether the output device uses a grid-based screen (such as a text terminal) or a bitmap screen (phones, monitors). Values are 0 for bitmap and 1 for grid-based.
No. The media feature is about the device’s screen type. CSS Grid layout uses properties like display: grid. Do not use this media feature to detect CSS Grid support.
The device is not grid-based — typical bitmap screens. Most laptops, phones, and monitors match (grid: 0).
The device is grid-based, such as text-only terminals or very basic fixed-font phones. Rare on modern consumer hardware.
Use @supports (display: grid) { … }, not @media (grid). The media feature answers a different question.
No. It is a CSS media feature evaluated by the browser layout engine, not a Node.js or server runtime feature.

Next: height

Query the viewport height with the CSS height media feature.

height tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful