Use Materialize CSS Grid Classes Instead of Custom Media Queries
Learn how Materialize CSS's responsive grid and visibility helpers let you define breakpoints in HTML, removing the need for scattered media queries.
20 Aug 2025, 13:34 UTC

The problem: media query drift
When building a responsive interface, it is common to sprinkle custom @media rules throughout a stylesheet to hide a sidebar, change column widths, or adjust card layouts. Over time these rules become scattered, making it hard to see which breakpoint triggers which change and increasing the risk of conflicts when the design evolves.
How Materialize’s mobile‑first grid works
Materialize provides a 12‑column fluid grid built from container, row, and col classes. Column width is expressed with a breakpoint prefix and a number from 1 to 12: s (small, ≤600 px), m (medium, 601‑992 px), l (large, 993‑1200 px), xl (extra‑large, >1200 px). The system is mobile‑first: an unprefixed or s class applies to all widths unless overridden by a larger breakpoint class. For example, col s12 m6 means full width on phones and half width on tablets and up.
Visibility helpers eliminate custom display toggles
Beyond the grid, Materialize ships helper classes such as hide-on-small-only, hide-on-med-and-up, show-on-large, and hide-on-xl-only. Adding one of these classes to an element toggles its visibility at the corresponding breakpoint without writing any CSS. This pairs naturally with grid decisions—for instance, collapsing a navigation sidebar on phones while keeping it visible on larger screens.
Worked example: responsive dashboard with sidebar and card grid
The following markup creates a layout where a sidebar disappears on small screens, the main area shifts from a single column to two columns at the medium breakpoint and to three columns at the large breakpoint, and a set of cards reflows accordingly. Place this inside a standard HTML file that includes the Materialize CSS stylesheet (via CDN or local copy) in the <head>.
<div class="container">
<div class="row">
<!-- Sidebar: hidden on small, 4 columns on medium, 3 columns on large -->
<aside class="col s12 m4 l3 hide-on-small-only">
<p>Navigation links</p>
</aside>
<!-- Main content: full width on small, 8 columns on medium, 9 columns on large -->
<main class="col s12 m8 l9">
<div class="row">
<!-- Cards: stacked on small, 2‑up on medium, 3‑up on large -->
<div class="col s12 m6 l4">Card 1</div>
<div class="col s12 m6 l4">Card 2</div>
<div class="col s12 m6 l4">Card 3</div>
</div>
</main>
</div>
</div>To verify the behavior, open the file in a browser and resize the window. You should observe the sidebar vanish near the 600 px width, the cards change from a single column to two columns around 600 px, and then to three columns near 992 px. Using the browser’s DevTools, inspect an element’s computed width to confirm that the framework’s grid classes are being applied and that no custom CSS is overriding them.
Trade‑offs and limitations
- Maintenance status: Materialize CSS has seen minimal activity since its 1.0.0 release in 2018. Treat it as effectively unmaintained; accessibility issues or JavaScript bugs are unlikely to be fixed upstream.
- Breakpoint lock‑in: The precompiled CDN CSS uses the default breakpoints. Changing them requires installing the Sass source and recompiling the framework.
- JavaScript initialization: CSS grid works automatically, but interactive components such as modals, sidenavs, and dropdowns must be initialized with
M.AutoInit()orM.ComponentName.init(); otherwise they appear styled but non‑functional. - Class‑name collisions: Avoid mixing Materialize with other frameworks that also use generic names like
rowandcol(e.g., Bootstrap) on the same page, as this leads to unpredictable layout behavior.
Actionable closing
For existing projects, audit your stylesheet for @media rules that merely adjust column widths or hide/show elements. Replace those rules with the appropriate s/m/l/xl grid classes and visibility helpers. For new projects, weigh the lack of active maintenance against your timeline; if you decide to use Materialize, keep layout concerns in the markup so a future migration to a maintained framework will involve mostly HTML changes rather than rewriting CSS.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.