A Prettier plugin that automatically sorts Bootstrap CSS classes following the framework's recommended order.
Works with HTML, JSX/TSX, Vue, Angular, and Astro templates.
npm install -D prettier-plugin-bootstrap
# or
pnpm add -D prettier-plugin-bootstrap
# or
yarn add -D prettier-plugin-bootstrapAdd the plugin to your Prettier configuration:
{
"plugins": ["prettier-plugin-bootstrap"]
}That's it! Your Bootstrap classes will now be automatically sorted on format.
<div class="text-center p-3 container bg-primary text-white mb-4 rounded"></div><div class="container bg-primary text-center text-white mb-4 p-3 rounded"></div>Classes are sorted following Bootstrap's architecture:
- Layout — containers, grid, columns
- Reboot / Typography — headings, lead, display
- Images — img-fluid, figures
- Tables — table variants
- Forms — form controls, selects, checks
- Buttons — btn variants
- Components — dropdowns, navs, cards, modals, etc. (alphabetical)
- Helpers — clearfix, stacks, visually-hidden
- Utilities — following the order in
scss/_utilities.scss
Within each group, responsive variants (sm, md, lg, xl, xxl) sort after the base class.
Unknown classes are preserved in their original relative order and placed after all known Bootstrap classes.
| Option | Type | Default | Description |
|---|---|---|---|
bootstrapAttributes |
string[] |
[] |
Additional HTML attributes to sort (beyond class and className) |
bootstrapFunctions |
string[] |
[] |
Function names whose arguments are class lists (e.g. clsx, classNames) |
{
"plugins": ["prettier-plugin-bootstrap"],
"bootstrapAttributes": ["ngClass", "v-bind:class"]
}html— HTML filesvue— Vue single-file componentsangular— Angular templatesbabel/babel-ts/typescript— JSX/TSX filesacorn/meriyah— Alternative JS parsersastro— Astro components (requiresprettier-plugin-astro)
When using with prettier-plugin-astro, list prettier-plugin-bootstrap after prettier-plugin-astro in your config so it can wrap the Astro parser:
{
"plugins": ["prettier-plugin-astro", "prettier-plugin-bootstrap"]
}pnpm install
pnpm run build
pnpm run test
pnpm run typecheck- Prettier >= 3.0.0
- Node.js >= 20
MIT