Gathering detailed insights and metrics for postcss-sort-media-queries
Gathering detailed insights and metrics for postcss-sort-media-queries
Gathering detailed insights and metrics for postcss-sort-media-queries
Gathering detailed insights and metrics for postcss-sort-media-queries
sort-css-media-queries
The custom `sort` method (mobile-first / desktop-first) of CSS media queries for `postcss-sort-media-queries`, `css-mqpacker` or `pleeease` (which uses css-mqpacker) or, perhaps, something else ))
@eslym/postcss-merge-queries
A PostCSS plugin to merge media queries and optionally sort them. Nested media queries are supported, including those in `@layer` rules.
PostCSS plugin for sorting and combining CSS media queries with mobile-first / desktop-first methodologies.
npm install postcss-sort-media-queries
Typescript
Module System
Min. Node Version
Node Version
NPM Version
98.2
Supply Chain
100
Quality
76.2
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
150 Stars
230 Commits
8 Forks
2 Watchers
4 Branches
5 Contributors
Updated on Jul 02, 2025
Latest Version
5.2.0
Package Id
postcss-sort-media-queries@5.2.0
Unpacked Size
12.67 kB
Size
4.27 kB
File Count
5
NPM Version
9.5.1
Node Version
18.16.0
Published on
May 30, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
1
🌏 English ▫ O'zbek
PostCSS plugin for sorting and combining CSS media queries with mobile first / desktop first methodologies.
From 5.0.0 plugin support Media Feature Types: “range”
And here is the online demo
before
1@media screen and (max-width: 640px) { 2 .head { color: #cfcfcf } 3} 4@media screen and (max-width: 768px) { 5 .footer { color: #cfcfcf } 6} 7@media screen and (max-width: 640px) { 8 .main { color: #cfcfcf } 9} 10@media screen and (min-width: 1280px) { 11 .mobile-first { color: #cfcfcf } 12} 13@media screen and (width > 640px) { 14 .mobile-first { color: #cfcfcf } 15} 16@media screen and (max-width: 640px) { 17 .footer { color: #cfcfcf } 18}
after
1@media screen and (width > 640px) { 2 .mobile-first { color: #cfcfcf } 3} 4@media screen and (min-width: 1280px) { 5 .mobile-first { color: #cfcfcf } 6} 7@media screen and (max-width: 768px) { 8 .footer { color: #cfcfcf } 9} 10@media screen and (max-width: 640px) { 11 /* combined */ 12 .head { color: #cfcfcf } 13 .main { color: #cfcfcf } 14 .footer { color: #cfcfcf } 15}
before
1@media screen and (width < 640px) { 2 .header { color: #cdcdcd } 3} 4@media screen and (min-width: 760px) { 5 .desktop-first { color: #cdcdcd } 6} 7@media screen and (width < 640px) { 8 .main { color: #cdcdcd } 9} 10@media screen and (min-width: 1280px) { 11 .desktop-first { color: #cdcdcd } 12} 13@media screen and (max-width: 760px) { 14 .footer { color: #cdcdcd } 15} 16@media screen and (max-width: 640px) { 17 .footer { color: #cdcdcd } 18}
after
1@media screen and (max-width: 760px) { 2 .footer { color: #cdcdcd } 3} 4@media screen and (width < 640px) { 5 /* combined */ 6 .header { color: #cdcdcd } 7 .main { color: #cdcdcd } 8 .footer { color: #cdcdcd } 9} 10@media screen and (min-width: 760px) { 11 .desktop-first { color: #cdcdcd } 12} 13@media screen and (min-width: 1280px) { 14 .desktop-first { color: #cdcdcd } 15}
First thing's, install the module:
npm install postcss postcss-sort-media-queries --save-dev
Check you project for existed PostCSS config: postcss.config.js
in the project root, "postcss"
section in package.json
or postcss
in bundle config.
If you already use PostCSS, add the plugin to plugins list:
1module.exports = { 2 plugins: [ 3+ require('postcss-sort-media-queries')({ 4+ sort: 'mobile-first', // default value 5+ }), 6 require('autoprefixer') 7 ] 8}
or with custom sort function
1module.exports = { 2 plugins: [ 3+ require('postcss-sort-media-queries')({ 4+ sort: function(a, b) { 5+ // custom sorting function 6+ } 7+ }), 8 require('autoprefixer') 9 ] 10}
If you do not use PostCSS, add it according to official docs and set this plugin in settings.
Sorting works based on dutchenkoOleg/sort-css-media-queries function.
This option support string or function values.
{string}
'mobile-first'
- (default) mobile first sorting{string}
'desktop-first'
- desktop first sorting{function}
your own sorting function'mobile-first'
1postcss([ 2 sortMediaQueries({ 3 sort: 'mobile-first' // default 4 }) 5]).process(css);
'desktop-first'
1postcss([ 2 sortMediaQueries({ 3 sort: 'desktop-first' 4 }) 5]).process(css);
1postcss([ 2 sortMediaQueries({ 3 function(a, b) { 4 return a.localeCompare(b); 5 } 6 }) 7]).process(css);
In this example, all your media queries will sort by A-Z order.
This sorting function is directly passed to Array#sort() method of an array of all your media queries.
By this configuration you can control sorting behaviour.
1postcss([ 2 sortMediaQueries({ 3 configuration: { 4 unitlessMqAlwaysFirst: true, // or false 5 } 6 }) 7]).process(css);
Or alternatively create a sort-css-mq.config.json
file in the root of your project. Or add property sortCssMQ: {}
in your package.json
.
Sort only top level media queries to prevent eject nested media queries from parent node
1postcss([ 2 sortMediaQueries({ 3 onlyTopLevel: true, 4 }) 5]).process(css);
See Releases history
postcss-momentum-scrolling
- plugin for adding momentum style scrolling behavior (-webkit-overflow-scrolling:touch
) for elements with overflow (scroll, auto) on iOSNo vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 2/20 approved changesets -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
12 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More