Breakpoints-js is a lightweight, pure javascript library for attaching callbacks to breakpoints.

Downloads in past


7611.0.66 years ago8 years agoMinified + gzip package size for breakpoints-js in KB


breakpoints-js is a lightweight, pure javascript library for attaching callbacks to breakpoints.

Table of contents

Main files

├── breakpoints.js
└── breakpoints.min.js

Quick start

Download the production versionmin or the development versionmax.

Install From Bower

bower install breakpoints.js --save

Install From Npm

npm install breakpoints-js --save

Install From Yarn

yarn add breakpoints-js

Build From Source

If you want build from source:
git clone
cd breakpoints-js
npm install
npm install -g gulp-cli babel-cli
gulp build



Before you try anything, you need to include breakpoints.js in your page.
<script src="breakpoints.min.js"></script>

You may need provide a matchMedia polyfill if you wish to support old/incapable browsers.
Then you can init the script easily by code
<script type="text/javascript">


There are some example usages that you can look at to get started. They can be found in the examples folder.


It will use the bootstrap media query breakpoints by default:
Breakpoints.defaults = {
    // Extra small devices (phones)
    xs: {
        min: 0,
        max: 767
    // Small devices (tablets)
    sm: {
        min: 768,
        max: 991
    // Medium devices (desktops)
    md: {
        min: 992,
        max: 1199,
    // Large devices (large desktops)
    lg: {
        min: 1200,
        max: Infinity

You can set up your own breakpoints when initialize it:
<script type="text/javascript">
        mobile: {
            min: 0,
            max: 767
        tablet: {
            min: 768,
            max: 991
        destop: {
            min: 992,
            max: Infinity



Check if the current screen is a specific size.'xs'); // return true or false


Return the size object that you can operate it handily.
// get size object
var sm = Breakpoints.get('sm');

// attach events
sm.on('enter', function(){
    // do something

// remove event handler'enter');

// get min width
sm.min // 768

// get max width
sm.max // 991

// get media query // "(min-width: 768px) and (max-width: 991px)"

// check if it's current size
sm.isMatched(); // true or false

// you can do in a chain
    enter: function(){

    leave: function(){



Return the current screen size object


Attach an event handler function for one or more events to the size
Breakpoints.on('md', {
    enter: function() {'enter '+;
    leave: function() {'leave '+;

Breakpoints.on('lg', 'enter', function(){'hello lg');

Passing data to the callback

Breakpoints.on('sm', "enter", {
    name: "Addy"
}, function(data) { + ' enter '+;

Breakpoints.on('sm', "leave", {
    name: "Karl"
}, function(data) { + ' leave '+;

Unite sizes

Breakpoints.on('md lg', {
    enter: function() {'enter '+;
    leave: function() {'leave '+;


The handler attached to the size will executed at most once.'md', 'enter', function(){'this only appear once when enter md');


Remove event handlers attached to size.
// remove all events attached to sm size'sm');

// remove all enter type events attached to md size'md', 'enter'); 

// remove specific event handler
var enterHandler = function(){};
Breakpoints.on('lg', 'enter', enterHandler);'lg', {
    enter: enterHandler

// alternative way'lg', 'enter', enterHandler);


Attach an event handler to the size change event
// attach handler to change event
Breakpoints.on('change', function(){'enter ' +;

// altrnative example
var changeHandler = function(){
    // do something 
Breakpoints.on('change', changeHandler);

// remove the handler'change', changeHandler);

// remove all change handlers'change');

Browser support

Tested on all major browsers.
| Safari | Chrome | Firefox | Edge | IE | Opera | |:--:|:--:|:--:|:--:|:--:|:--:| | Latest ✓ | Latest ✓ | Latest ✓ | Latest ✓ | 9-11 ✓ | Latest ✓ |
  • matchMedia browser support work perfect on all modern browsers (IE10+, firefox, chrome, android and safari).
  • With some polyfills (like the ones included in matchMedia.js) Breakpoints works perfect in IE6-9 as well.


Anyone and everyone is welcome to contribute. Please take a moment to review the guidelines for contributing. Make sure you're using the latest version of jquery-scrollTo before submitting an issue. There are several ways to help out:


jquery-scrollTo is built modularly and uses Gulp as a build system to build its distributable files. To install the necessary dependencies for the build system, please run:
npm install -g gulp
npm install -g babel-cli
npm install

Then you can generate new distributable files from the sources, using:
gulp build

More gulp tasks can be found here.


To see the list of recent changes, see Releases section.

Other Projects

If you like this project then I encourage you to check out a few of my other hand-selected projects.
  • enquire.js - A lightweight, pure JavaScript library for responding to CSS media queries.
  • mediaquery - A jQuery plugin for responsive media query events.
  • strapPoint - A small jQuery utility plugin to make working with Bootstrap breakpoints easier.
  • pointbreak.js - It provides a friendly interface to matchMedia with named media queries and easy to create callbacks.

Copyright and license

Copyright (C) 2016 amazingSurge.
Licensed under the LGPL license.
⬆ back to top