Media Query Sass Mixin [code snippet]


Media Query Sass Mixin [code snippet]

The sass mixin below has default variable values for common breakpoints. But this mixin also allows you to write a custom value if needed.

// default breakpknts
$xs: "480px";
$sm: "600px";
$md: "799px";
$lg: "1010px";
$xl: "1280px";

@mixin media-min($size) {
  @media (min-width: $size) {
    @content;
  }
}
@mixin media-max($size) {
  @media (max-width: $size) {
    @content;
  }
}

// Using a variable
@include media-max($sm) { 
    body {color:red}
}

// Custom value 
@include media-min(300px) { 
    body {color:red}
}

 



Written by: Jake Lett
Jake Lett is a results-driven B2B marketing consultant with 15+ years of experience helping businesses boost online visibility, generate qualified leads, and increase sales. Specializing in SEO, HubSpot, and PPC campaign management, Jake leverages proven strategies to deliver measurable growth. As a Certified Google Ads Specialist and HubSpot Developer, he is committed to driving impactful results for his clients.

Related posts

Tags:

Want to Get Email Updates of New Articles?

Join My Email Newsletter