A single, well-designed responsive mixin eliminates hardcoded pixel values from every component in a project. This lesson builds a respond-to() mixin step by step, including variants for max-width queries and between-range queries.
Building a Basic respond-to() Mixin
The core idea: accept a breakpoint name, look it up in a shared map, and wrap the caller's styles in the resulting media query using @content. Every component then calls this one mixin instead of writing raw media queries.
The mixin call reads like a sentence: "respond to md and up."
Any number of declarations can go inside the passed content block.
The mixin can be extended with additional parameters for direction (min/max) or ranges.
Centralizing this logic in one mixin means updating a breakpoint value in one place updates every usage.
Responsive Mixins Cheatsheet
Common variants of a breakpoint mixin for different query needs.
Mixin Call
Generated Query
Use Case
respond-to(md)
(min-width: 768px)
Mobile-first "and up" (default)
respond-below(md)
(max-width: 767px)
Desktop-first "and below"
respond-between(sm, lg)
(min-width: 576px) and (max-width: 991px)
A specific range only
respond-to(md, max)
(max-width: 768px)
Explicit direction parameter variant
Adding a max-width Variant
Even in a primarily mobile-first project, you'll occasionally need to target "below a breakpoint" instead of "at or above it." A companion mixin keeps this consistent instead of writing a one-off raw query.
Occasionally a style needs to apply only within a specific range, common for tablet-only adjustments. A respond-between() mixin combines both bounds into one media query.
In practice, this mixin lives inside abstracts/_mixins.scss and is @used wherever needed, exactly the pattern covered in the Project Structure and 7-1 Pattern lessons.
Writing raw @media queries in individual components after already building a shared mixin, defeating its purpose.
Forgetting the - 1px adjustment in a max-width variant, causing an overlapping range with the min-width breakpoint above it.
Not validating the breakpoint name argument, letting a typo silently produce broken or missing responsive behavior.
Building too many highly specific mixin variants instead of a small, well-designed core set (respond-to, respond-below, respond-between).
Key Takeaways
A shared respond-to() mixin eliminates hardcoded pixel values across a project's components.
Companion mixins (respond-below, respond-between) cover max-width and range-based needs consistently.
Validating breakpoint names with @error catches typos at compile time instead of producing silently broken CSS.
These mixins belong in a shared abstracts partial, loaded wherever a component needs responsive behavior.
Pro Tip
Build exactly three responsive mixins for most projects, respond-to (min-width), respond-below (max-width), and respond-between (range), and resist the urge to add more variants until a real, recurring need appears.
You now know how to build reusable responsive mixins. Next, learn how to choose and define a sensible breakpoint scale for your project.