Skip to content

useSortedProperties

.vscode/settings.json
{
"editor.codeActionsOnSave": {
"source.action.useSortedProperties.biome": "explicit",
"source.fixAll.biome": "explicit"
}
}

Enforce ordering of CSS properties and nested rules.

This rule ensures the contents of a CSS rule are ordered consistently.

Properties are ordered semantically, with more important properties near the top and similar properties grouped together. Nested rules and at-rules are placed after properties.

The ordering is roughly:

  1. Custom properties
  2. Layout properties (display, flex, grid)
  3. Margin and padding properties
  4. Typography properties (font, color)
  5. Interaction properties (pointer-events, visibility)
  6. Background and border properties
  7. Transition and animation properties
  8. Nested rules, media queries and other at-rules
p {
transition: opacity 1s ease;
border: 1px solid black;
pointer-events: none;
color: black;
margin: 8px;
display: block;
--custom: 100;
}
code-block.css:1:3 assist/source/useSortedProperties  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

The properties are not sorted.

> 1 │ p {
^
> 2 │ transition: opacity 1s ease;
> 3 │ border: 1px solid black;
> 4 │ pointer-events: none;
> 5 │ color: black;
> 6 │ margin: 8px;
> 7 │ display: block;
> 8 │ —custom: 100;
> 9 │ }
^
10 │

Safe fix: Sort these properties

1 1 p {
2 - ··transition:·opacity·1s·ease;
3 - ··border:·1px·solid·black;
4 - ··pointer-events:·none;
2+ ··--custom:·100;
3+ ··display:·block;
4+ ··margin:·8px;
5 5 color: black;
6 - ··margin:·8px;
7 - ··display:·block;
8 - ··--custom:·100;
6+ ··pointer-events:·none;
7+ ··border:·1px·solid·black;
8+ ··transition:·opacity·1s·ease;
9 9 }
10 10

p {
span { color: blue; }
color: red;
}
code-block.css:1:3 assist/source/useSortedProperties  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

The properties are not sorted.

> 1 │ p {
^
> 2 │ span { color: blue; }
> 3 │ color: red;
> 4 │ }
^
5 │

Safe fix: Sort these properties

1 1 p {
2 - ··span·{·color:·blue;·}
3 - ··color:·red;
2+ ··color:·red;
3+ ··span·{·color:·blue;·}
4 4 }
5 5

p {
--custom: 100;
display: block;
margin: 8px;
color: black;
pointer-events: none;
border: 1px solid black;
transition: opacity 1s ease;
}
p {
color: red;
span { color: blue; }
}
biome.json
{
"assist": {
"actions": {
"source": {
"useSortedProperties": "on"
}
}
}
}