Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>CSS Sort By ClassnameNew to Visual Studio Code? Get it now.
CSS Sort By Classname

CSS Sort By Classname

bonham000

|
1,880 installs
| (5) | Free
Sort classnames in a CSS file alphabetically.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

CSS Sort By Classname

This is a VS Code extension to sort a .css file alphabetically by classname. It was adapted from the css-dictionary extension first built by @waleedj99.

This extension sorts an entire CSS file, applying the following rules:

  • All @keyframes declarations are moved to the top of the file.
  • All @media media query declarations are moved to the bottom of the file.
  • All remaining CSS declarations are sorted alphabetically by classname and moved to the middle of the file.
  • Original comments are preserved.

Note that there are some edge cases which this may not handle very well and potentially result in mangled CSS output. A brief visual inspection of the results after sorting is recommended.

Demo

css-sort-demo

Features

Run the extension from the command menu under "CSS Sort by Classname" with a .css file open. The entire file will be sorted. There is no option to sort a sub-selection of the file.

Requirements

Only .css files are supported.

Extension Settings

n/a

Debugging

If there are issues or you want to modify/extend this project, there are unit tests in the src/test/unit folder which allow you to quickly run the CSS sorting logic and print out results for debugging. You can run these with the yarn test:unit command.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft