# Responsive Breakpoints in Sass

- Link: https://cagrimmett.com/2017/12/18/breakpoints-sass/
- Published: 2017-12-18T22:26:00-05:00
- Author: Chuck Grimmett

Up until last week, Sass breakpoints were a bit of a mystery to me. I finally figured
out how they work.

First, they are programmatically generated. Define the breakpoints as a [map](http://sass-lang.com/documentation/file.SASS_REFERENCE.html#Maps).
[I use the list here.](https://pacoup.com/2011/06/12/list-of-true-169-resolutions/)

    ```language-sass
    $breakpoints: ( 	xs: 512px, 	sm: 768px, 	md: 896px, 	lg: 1152px, 	xl: 1280px );
    ```

Next, use a [mixin](http://sass-lang.com/documentation/file.SASS_REFERENCE.html#Mixin_Directives__mixins)
and [expressions](http://sass-lang.com/documentation/file.SASS_REFERENCE.html#Control_Directives___Expressions)
to build the media queries. I use `min-width`. I leave it as an exercise for the
reader if you wish to reverse this to use `max-width` instead.

    ```language-sass
    @mixin breakpoint( $breakpoint ) {     @if map-has-key( $breakpoints, $breakpoint ) {         @media ( min-width: #{ map-get( $breakpoints, $breakpoint ) } ) {             @content;         }     } @else if type_of( $breakpoint ) == number and unit( $breakpoint ) == px or unit( $breakpoint ) == em or unit( $breakpoint ) == rem {         @media (min-width: $breakpoint ) {             @content;         }     } @else {         @warn "No value could be retrieved from `#{$breakpoint}`. "                + "It is either not defined in the `$breakpoints` map, or it is an invalid number of px, em, or rem.";     } }
    ```

To use, define your breakpoint styles using [@import](http://sass-lang.com/documentation/file.SASS_REFERENCE.html#_import__import).
Here is an example defining H1 font sizes at three different breakpoints:

    ```language-sass
    h1 { 		text-transform: capitalize; 		@include breakpoint(xs) { 				font-size: 2.2em; 		} 		@include breakpoint(sm) { 				font-size: 2.7em; 		} 		@include breakpoint(xl) { 				font-size: 3em; 		} }
    ```

![](https://i0.wp.com/cagrimmett.com/wp-content/uploads/2020/09/breakpoints-sass.
png?ssl=1)
