Quasar visibility classes hide or show an element with nothing but a class name: gt-sm to show navigation links from tablet-landscape width up, lt-md for the menu button that replaces them, desktop-only for a keyboard shortcut hint. They work before any JavaScript runs, which makes them the right default for responsive markup. They also have sharp edges: some react to the window width and some to the device, and a hidden element is still rendered. This post covers both kinds, when to reach for $q.screen instead, and the mistakes worth avoiding. All of it is checked against the Quasar 2.35.2 CSS.
| Kind | Examples | Decided by | Changes when |
|---|---|---|---|
| Size | xs, gt-sm, lt-md | Window width (media queries) | You resize the window |
| Platform | desktop-only, mobile-hide, touch-only | The device, through classes Quasar adds to <body> | Not when you resize |
They're often treated as the same thing ("hide on mobile"), and that's the first pitfall. A narrow desktop window is xs and desktop at the same time.
The size classes use the five Quasar breakpoints:
| Breakpoint | From | To |
|---|---|---|
xs | 0px | 599.98px |
sm | 600px | 1023.98px |
md | 1024px | 1439.98px |
lg | 1440px | 1919.98px |
xl | 1920px | no limit |
How the thresholds work, what $q.screen reports and how to change the numbers is the topic of the Quasar breakpoints post. Here we need the class names built on them:
| Class | Visible on |
|---|---|
xs, sm, md, lg, xl | That one breakpoint only |
lt-sm | xs |
lt-md | xs, sm (below 1024px) |
lt-lg | xs, sm, md |
lt-xl | everything below 1920px |
gt-xs | sm and up (600px and wider) |
gt-sm | md and up (1024px and wider) |
gt-md | lg and up |
gt-lg | xl |
lt reads "lower than" and gt reads "greater than". The pair you'll use most is gt-sm and lt-md: they split the same line at 1024px, so exactly one of them is visible at any width.
<template>
<q-toolbar>
<q-btn class="lt-md" flat round icon="menu" aria-label="Open menu" @click="drawer = true" />
<q-toolbar-title shrink>Acme</q-toolbar-title>
<div class="gt-sm row q-gutter-sm q-ml-md">
<q-btn flat no-caps label="Product" to="/product" />
<q-btn flat no-caps label="Pricing" to="/pricing" />
<q-btn flat no-caps label="Docs" to="/docs" />
</div>
<q-space />
<q-btn unelevated color="primary" no-caps label="Sign up" to="/signup" />
</q-toolbar>
</template>Under the hood each class is a media query that sets display: none !important outside its range. Inside its range the class adds nothing, so the element keeps its own display: the row above is still a flex container from 1024px up.
The size classes use the same names as the grid (col-md-6), but they read differently. col-md-6 means "from md up". The class md on its own means "only on md", so it disappears again at 1440px. If you want "from md up", that's gt-sm. When in doubt, open the Breakpoint Visualizer, resize the window, and read its visibility classes panel, which marks each of xs to xl, lt-* and gt-* as showing or hiding at the current width. It also works the other way: pick the sizes an element should appear on and it writes the class.
Two more classes don't depend on the screen at all. hidden sets display: none, so the element takes no space. invisible sets visibility: hidden, so it keeps its space but can't be seen. invisible is the one for keeping a layout from jumping, like reserving room for a spinner.
Quasar's Platform detection adds classes to <body> (on the server too, from the user agent): desktop or mobile, touch or no-touch, and on matching platforms platform-ios, platform-android, electron, cordova, capacitor, native-mobile and within-iframe. The platform classes key off those:
| Show only on | Hide on |
|---|---|
desktop-only | desktop-hide |
mobile-only | mobile-hide |
touch-only | touch-hide |
platform-ios-only, platform-android-only | platform-ios-hide, platform-android-hide |
native-mobile-only, cordova-only, capacitor-only | native-mobile-hide, cordova-hide, capacitor-hide |
electron-only | electron-hide |
within-iframe-only | within-iframe-hide |
Use them for things that depend on the device, not the space available:
<template>
<div class="text-caption text-grey-7">
<span class="desktop-only">Press <kbd>Ctrl</kbd> + <kbd>K</kbd> to search</span>
<span class="mobile-only">Tap the search icon to search</span>
</div>
<q-btn class="capacitor-hide" flat no-caps label="Get the app" href="/app" />
</template>The keyboard hint is a good fit: a phone has no Ctrl key however wide it is, and a desktop browser does however narrow. The "Get the app" button hides itself inside your own Capacitor build.
desktop and mobile come from the user agent. A laptop with a small window is still desktop, so mobile-only never shows there. That's why "hide on mobile" for layout reasons should be a size class (gt-xs or gt-sm), and "hide on mobile" for capability reasons a platform class.
Two cases to know:
desktop, and the classes switch once the app starts.desktop and touch. touch-only shows there, mobile-only doesn't.gt-sm and lt-md don't remove anything; both versions are in the DOM and the inactive one is hidden with CSS. That's harmless for a menu button. It's a problem when:
q-table with hundreds of rows rendered twice, once for mobile and once for desktop.q-inputs bound to the same model, one hidden, both validated by the surrounding q-form.id. Two copies, two identical ids.For those, render only one copy with v-if and $q.screen:
<script setup lang="ts">
import { useQuasar } from 'quasar'
const $q = useQuasar()
</script>
<template>
<SalesChart v-if="$q.screen.gt.sm" />
<SalesSummaryList v-else />
</template>The trade-off: with server rendering, $q.screen reports xs until the app has hydrated, so the server HTML contains the mobile version and desktop visitors see the swap. Put v-if switches below the fold, or accept the swap, and keep CSS classes for everything visible on the first paint.
A hidden element is out of the tab order and the accessibility tree, which is usually what you want. But it means the two versions must carry the same information. If the desktop header has a "Docs" link and the mobile drawer doesn't, mobile and screen reader users at that width lose it.
The hiding rule uses !important. If an element has lt-md and you set display: flex on it yourself, it still disappears from 1024px up. To change that, change the class, not the specificity.
q-drawer, q-header and q-footer take part in the q-layout size calculations. Hiding a drawer with gt-sm hides its content, but the layout can still reserve space for it. Use the drawer's own props instead (breakpoint, show-if-above, behavior), and visibility classes for the content inside.
Two smaller groups complete the set:
orientation-portrait and orientation-landscape use the orientation media query, which compares the window's height and width.print-only and print-hide show or hide content when the page is printed. print-hide on the header, drawer and action buttons gives you a clean printout of an invoice page without a print stylesheet.How do I hide something on mobile in Quasar? For small screens, use gt-xs (hidden below 600px) or gt-sm (hidden below 1024px). For mobile devices whatever their width, use mobile-hide.
What is the difference between gt-sm and lt-md? They're opposites: gt-sm shows from 1024px up and lt-md below 1024px.
Why is my lt-md element still visible on a desktop? Check the window width, not the screen. A desktop window narrower than 1024px is sm, so lt-md applies. The Breakpoint Visualizer shows the current width and breakpoint.
Can I use v-show with $q.screen instead? You can, but it combines the downsides: both copies are rendered and the visibility still waits for JavaScript. Use a class or v-if.
Keep the Breakpoint Visualizer open while you add visibility classes. Drag the window across 600px, 1024px and 1440px and you'll see exactly which breakpoint, and so which classes, apply at each width.