Skip to content

useSortedAttributes (HTML)

.vscode/settings.json
{
"editor.codeActionsOnSave": {
"source.action.useSortedAttributes.biome": "explicit",
"source.fixAll.biome": "explicit"
}
}
biome.json
{
"assist": {
"actions": {
"source": {
"useSortedAttributes": "on"
}
}
}
}

Sort HTML attributes and framework directives into a consistent order.

Regular HTML attributes and Astro directives are sorted by name. Svelte directives follow the order from eslint-plugin-svelte’s sort-attributes rule, and Vue directives follow the Vue attribute-order convention. Attributes within the same category use the configured sortOrder.

A spread attribute or Vue’s v-bind="object" can provide or replace several attributes. The action leaves each spread in place and sorts only the consecutive attributes on either side, preserving override behavior.

<input type="text" id="name" name="name" />
code-block.html:1:1 assist/source/useSortedAttributes  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ The attributes are not sorted.

> 1 │ <input type="text" id="name" name="name" />
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ Safe fix: Sort the HTML attributes.

1 │ - <input·type="text"·id="name"·name="name"·/>
1 │ + <input·id="name"·name="name"·type="text"·/>
2 2 │

<textarea id="mytextarea" name="textarea" rows="5" cols="20" data-1="" data-11="" data-12="" data-2="">Hello, world!</textarea>
code-block.html:1:1 assist/source/useSortedAttributes  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ The attributes are not sorted.

> 1 │ <textarea id="mytextarea" name="textarea" rows="5" cols="20" data-1="" data-11="" data-12="" data-2="">Hello, world!</textarea>
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ Safe fix: Sort the HTML attributes.

1 │ - <textarea·id="mytextarea"·name="textarea"·rows="5"·cols="20"·data-1=""·data-11=""·data-12=""·data-2="">Hello,·world!</textarea>
1 │ + <textarea·cols="20"·data-1=""·data-2=""·data-11=""·data-12=""·id="mytextarea"·name="textarea"·rows="5"·>Hello,·world!</textarea>
2 2 │

<svg slot="fallback" class="generic-avatar" transition:name="avatar">...</svg>
code-block.astro:1:3 assist/source/useSortedAttributes  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ The attributes are not sorted.

> 1 │ <svg slot="fallback" class="generic-avatar" transition:name="avatar">...</svg>
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ Safe fix: Sort the HTML attributes.

1 │ - ··<svg·slot="fallback"·class="generic-avatar"·transition:name="avatar">...</svg>
1 │ + ··<svg·class="generic-avatar"·slot="fallback"·transition:name="avatar">...</svg>
2 2 │

<input type="range" bind:value={b} min="0" max="10" />
code-block.svelte:1:4 assist/source/useSortedAttributes  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ The attributes are not sorted.

> 1 │ <input type="range" bind:value={b} min="0" max="10" />
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ Safe fix: Sort the HTML attributes.

1 │ - ··→ <input·type="range"·bind:value={b}·min="0"·max="10"·/>
1 │ + ··→ <input·max="10"·min="0"·type="range"·bind:value={b}·/>
2 2 │

<div bind:value2={a} bind:value1={a} {...props} style:color="red">...</div>
code-block.svelte:1:4 assist/source/useSortedAttributes  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ The attributes are not sorted.

> 1 │ <div bind:value2={a} bind:value1={a} {...props} style:color="red">...</div>
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ Safe fix: Sort the HTML attributes.

1 │ - ··→ <div·bind:value2={a}·bind:value1={a}·{...props}·style:color="red">...</div>
1 │ + ··→ <div·bind:value1={a}·bind:value2={a}·{...props}·style:color="red">...</div>
2 2 │

<input @input="onInput" :value="text" placeholder="Type here">
code-block.vue:1:4 assist/source/useSortedAttributes  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ The attributes are not sorted.

> 1 │ <input @input="onInput" :value="text" placeholder="Type here">
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ Safe fix: Sort the HTML attributes.

1 │ - ··→ <input·@input="onInput"·:value="text"·placeholder="Type·here">
1 │ + ··→ <input·placeholder="Type·here"·:value="text"·@input="onInput"·>
2 2 │

<input id="name" name="name" type="text" />
<textarea cols="20" data-1="" data-2="" data-11="" data-12="" id="mytextarea" name="textarea" rows="5">Hello, world!</textarea>
<svg class="generic-avatar" slot="fallback" transition:name="avatar">...</svg>
<input max="10" min="0" type="range" bind:value={b} />
<div bind:value1={a} bind:value2={a} {...props} style:color="red">...</div>
<input placeholder="Type here" :value="text" @input="onInput" >

Selects natural or lexicographic ordering. Natural ordering compares numbers by value, so data-2 comes before data-11, and is the default. Lexicographic ordering compares names character by character.

The following configuration uses lexicographic order:

biome.json
{
"assist": {
"actions": {
"source": {
"useSortedAttributes": {
"level": "on",
"options": {
"sortOrder": "lexicographic"
}
}
}
}
}
}
<textarea id="mytextarea" name="textarea" rows="5" cols="20" data-1="" data-2="" data-11="" data-12="">Hello, world!</textarea>
code-block.html ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ Source action diff:

1 │ - <textarea·id="mytextarea"·name="textarea"·rows="5"·cols="20"·data-1=""·data-2=""·data-11=""·data-12="">Hello,·world!</textarea>
1 │ + <textarea·cols="20"·data-1=""·data-11=""·data-12=""·data-2=""·id="mytextarea"·name="textarea"·rows="5"·>Hello,·world!</textarea>
2 2 │

A list of attribute names that should be sorted before all other attributes, in the order they appear in this list. The remaining attributes are sorted after the listed ones. Listed attributes take precedence over the category-based ordering.

biome.json
{
"assist": {
"actions": {
"source": {
"useSortedAttributes": {
"level": "on",
"options": {
"sortFirst": [
"type"
]
}
}
}
}
}
}
<input id="name" name="name" type="text" />
code-block.html:1:1 assist/source/useSortedAttributes  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ The attributes are not sorted.

> 1 │ <input id="name" name="name" type="text" />
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ Safe fix: Sort the HTML attributes.

1 │ - <input·id="name"·name="name"·type="text"·/>
1 │ + <input·type="text"·id="name"·name="name"·/>
2 2 │