1.0.1 • Public • Published

Vue 3 Breakpoints

JavaScript-based Media Queries for Vue 3. Internally uses window.matchMedia and the Composition API.


NPM: npm i vue-next-breakpoints

Yarn: yarn add vue-next-breakpoints


    <desktop-nav v-if="breakpoints.desktop.matches" />
    <mobile-nav v-if="" />
import useBreakpoints from "vue-next-breakpoints";
export default {
    name: "YourComponent",
    setup() {
        // Define your breakpoints with any name
        const breakpoints = useBreakpoints({
            mobile: 600, // max-width: 600px
            desktop: [601] // min-width: 601px
        return {
            // If you want to use different key, feel free do do so, e.g.:
            // mediaqueries: breakpoints
            // and then use mediaqueries.desktop.matches etc.
    created() {
        // Event listeners are optional but may come in handy.
        // You can register them inside setup, created or mounted methods."enter", (mq) => {
            console.log("Entered mobile breakpoint");
            console.log("Media Query", mq);
"leave", (mq) => {
            console.log("Left mobile breakpoint");
            console.log("Media Query", mq);

Options and methods

1. Defining breakpoints

Simply pass an object with key-value pairs to useBreakpoints function, where the key is any name you want and the value is one of the following:

  • numeric value, e.g. 200 which converts to @media screen and (max-width: 200px)
  • string value with any units you prefer, e.g. 80% which converts to @media screen and (max-width: 80%)
  • an array with one of the above values, e.g. [600] which converts to @media screen and (min-width: 600px)
  • an array with two of the above values, e.g. [601, "1200px"] which converts to @media screen and (min-width: 601px) and (max-width: 1200px)
  • any other media query, e.g. @media screen and (-webkit-min-device-pixel-ratio: 1) which will not be converted in any way (@media prefix is not required, e.g. @media print is the same as just print).

2. Determining media query state

Each of the specified media queries have .matches property which is either true or false. You can use them in a template or in any other method, computed property etc:

    <desktop-nav v-if="breakpoints.desktop.matches" />
    <mobile-nav v-if="" />

3. Assigning event listeners

In most cases using .matches property will be enough, but if you want to listen for the specific breakpoint, there are two types of listeners: "enter" and "leave" and these can be assigned to any media query previously configured.

const enterCallback = (mq) => {
    console.log("Entered mobile breakpoint");
    console.log("Media Query", mq);
const leaveCallback = (mq) => {
    console.log("Left mobile breakpoint");
    console.log("Media Query", mq);
created() {"enter", enterCallback);"leave", leaveCallback);

Event listener can be easily removed as well:"enter", enterCallback);

You don't have to remove those event listeners manually before the component is unmounted, it's done automatically behind the scenes.

If you don't specify the callback to remove, all listeners of the given type will be removed:"enter"); // all previously assigned listeners are gone


If you find any problems using this library or you want to propose new features to it, feel free to open an issue on Github.

Package Sidebar


npm i vue-next-breakpoints

Weekly Downloads






Unpacked Size

17.8 kB

Total Files


Last publish


  • piotrpalarz