β Blogs
How to use SCSS media queries efficiently in your react project (Desktop-First) ?
π₯ Desktop First (Mandatory)
β Best for:
| Device Type | Breakpoint Name | Width (max-width) |
|---|---|---|
| Large Screens | xxl | >= 1400px (base) |
| Desktop | xl | 1200px |
| Laptop | lg | 992px |
| Tablet | md | 768px |
| Mobile | sm | 576px |
| Small Mobile | xs | 480px |
$breakpoints: (
xxs: (
min: 320px,
max: 319.98px,
),
xs: (
min: 450px,
max: 449.98px,
),
sm: (
min: 576px,
max: 575.98px,
),
md: (
min: 769px,
max: 768.98px,
),
lg: (
min: 992px,
max: 991.98px,
),
xl: (
min: 1200px,
max: 1199.98px,
),
xxl: (
min: 1400px,
max: 1399.98px,
),
);
@mixin breakpoint($breakpoint, $direction: min) {
@if map.has-key($breakpoints, $breakpoint) {
$values: map.get($breakpoints, $breakpoint);
$min: map.get($values, min);
$max: map.get($values, max);
@if $direction == min {
@media (min-width: $min) {
@content;
}
} @else {
@media (max-width: $max) {
@content;
}
}
} @else {
@if $direction == min {
@media (min-width: $breakpoint) {
@content;
}
} @else {
@media (max-width: $breakpoint) {
@content;
}
}
}
}
π« Raw media queries should be avoided.
// β Not allowed
@media (max-width: 768px) {}
β Always use mixin
@include breakpoint("md", min) {}
.container {
padding: 24px;
font-size: 24px;
display: flex;
gap: 24px;
margin-top: 4rem;
}
// Mobile / Table Styles
@include breakpoint('md', max) {
.container {
padding: 16px;
font-size: 18px;
margin-top: 3.2rem;
}
}
@include breakpoint('sm', max) {
.container {
padding: 12px;
font-size: 14px;
margin-top: 2.4rem;
}
}
// or the best way to do will be like this, nest media queries
@include breakpoint('md', max) {
.container {
padding: 16px;
font-size: 18px;
margin-top: 3.2rem;
}
@include breakpoint('sm', max) {
.container {
padding: 12px;
font-size: 14px;
margin-top: 2.4rem;
}
}
}
// this way the md breakpoint will not overlap it's styles over sm breakpoin
π₯ Desktop (Default)
.layout {
display: grid;
grid-template-columns: repeat(4, 1fr);
}
π₯ Laptop (lg)
1. Reduce Spacing
2. Maintain multi-column layout
@include respond-down(lg) {
.layout {
grid-template-columns: repeat(3, 1fr);
}
}
π± Tablet (md)
1. Reduce Columns
2. Increase tap targets
@include respond-down(md) {
.layout {
grid-template-columns: repeat(2, 1fr);
}
}
π± Mobile (sm)
1. Single column
2. Stack content vertically
3. Disable hover only interactions
@include respond-down(sm) {
.layout {
grid-template-columns: 1fr;
}
}
β Must Follow
β Desktop styles without media queries
β Only max-width queries
β Centralized breakpoint definitions
β Component level media queries
β Avoid
β Mixing min-width and max-width
β Device-specific names (ipad, iphone)
β Overriding entire components for small changes
styles/
βββ abstracts/
β βββ _breakpoints.scss
β βββ _media.scss
β βββ _abstracts-dir.scss
βββ base/
β βββ _fonts.scss
β βββ _typography.scss
β βββ _colors.scss
β βββ _base-dir.scss
βββ components/
β βββ _card.scss
β βββ _button.scss
β βββ _components-dir.scss
βββ pages/
β βββ _home.scss
β βββ _about.scss
β βββ _pages-dir.scss
βββ layout/
β βββ _footer.scss
β βββ _header.scss
β βββ _layout-dir.scss
βββ style.scss
@use './card';
@use './button';
@charset "UTF-8"; // for special characters if your stylesheet includes special characters like βΉ βΉ β¬ Β₯"
@use "base/base-dir";
@use "abstracts/abstracts-dir";
@use "components/components-dir";
@use "layouts/layout-dir";
@use "pages/pages-dir";
π« Avoid for:
Want to work together?
Get answers and advice from people you want it from. Techsphere designers and developers will help you create awesome softwares based on your requirements.

