DEV Community

Cover image for Creating Custom SCSS Breakpoints for Responsive Design
JOYDIP PAUL
JOYDIP PAUL

Posted on

Creating Custom SCSS Breakpoints for Responsive Design

In modern web development, responsive design ensures a seamless user experience across different screen sizes. SCSS provides a powerful way to manage breakpoints efficiently with mixins. In this blog, we will explore how to create custom SCSS breakpoints using mixins for flexible and maintainable styles.

Why Use Custom SCSS Breakpoints?

Using custom breakpoints in SCSS allows you to:

Maintain cleaner and more readable code.

Apply media queries efficiently without repetition.

Easily adjust styles for different screen sizes by reusing mixins.

Creating the Custom SCSS Breakpoints

We will define two mixins: one for minimum-width breakpoints and another for maximum-width breakpoints.

SCSS Mixin for Min-Width Breakpoints

This mixin applies styles when the viewport is at least a specified width.

@mixin breakpoint-min($width) {
    @media only screen and (min-width: $width) {
        @content;
    }
}
Enter fullscreen mode Exit fullscreen mode

SCSS Mixin for Max-Width Breakpoints

This mixin applies styles when the viewport is at most a specified width.

@mixin breakpoint-max($width) {
    @media only screen and (max-width: $width) {
        @content;
    }
}
Enter fullscreen mode Exit fullscreen mode

Using the SCSS Breakpoint Mixins

Now, let’s see how we can use these mixins to apply responsive styles.

Example: Styling for Mobile and Tablet Screens

@include breakpoint-max(767px) {
    body {
        background-color: lightgray;
    }
}
Enter fullscreen mode Exit fullscreen mode
@include breakpoint-max(991px) {
     body {
        background-color: recebapurple;
    }
}
Enter fullscreen mode Exit fullscreen mode

Example: Applying Min-Width Breakpoints

@include breakpoint-min(1024px) {
    .navbar {
        display: flex;
    }
}
Enter fullscreen mode Exit fullscreen mode
  1. Applies Styles at 1024px and Above – The mixin ensures the styles inside it take effect only when the screen width is 1024px or larger.
  2. Uses a Custom Mixin – Calls breakpoint-min(1024px), which generates a min-width media query.
  3. Enables Flexbox for Navbar – The .navbar gets display: flex, making it a flexbox container for better alignment.
  4. Supports Responsive Design – Helps transition from a mobile-friendly layout to a more structured navbar on larger screens.
  5. Keeps Code Clean & Reusable – Using mixins avoids repetition and makes managing breakpoints easier and more maintainable.

Benefits of Using SCSS Breakpoint Mixins

Reusability: Define breakpoints once and use them throughout your stylesheets.

Readability: Improves code organization and avoids redundant media queries.

Maintainability: Easily modify breakpoints in a single place without affecting multiple files.

Conclusion

Using SCSS mixins for breakpoints enhances your workflow and helps maintain a scalable and well-structured codebase. Implementing custom breakpoint mixins ensures consistency and flexibility in your responsive designs.

Give these mixins a try in your next project and experience the benefits of writing cleaner, more efficient SCSS!

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

The best way to debug slow web pages cover image

The best way to debug slow web pages

Tools like Page Speed Insights and Google Lighthouse are great for providing advice for front end performance issues. But what these tools can’t do, is evaluate performance across your entire stack of distributed services and applications.

Watch video

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay