diff --git a/.changeset/rotten-pans-ring.md b/.changeset/rotten-pans-ring.md
new file mode 100644
index 000000000000..2f4d99ca4564
--- /dev/null
+++ b/.changeset/rotten-pans-ring.md
@@ -0,0 +1,10 @@
+---
+"@biomejs/biome": patch
+---
+
+Fixed an issue with the HTML formatter where it wouldn't add a space before the `/>` in self closing elements. This brings the HTML formatter more in line with Prettier.
+
+```diff
+-
++
+```
diff --git a/crates/biome_html_formatter/src/html/auxiliary/self_closing_element.rs b/crates/biome_html_formatter/src/html/auxiliary/self_closing_element.rs
index db1694a42da6..d250ffe28b80 100644
--- a/crates/biome_html_formatter/src/html/auxiliary/self_closing_element.rs
+++ b/crates/biome_html_formatter/src/html/auxiliary/self_closing_element.rs
@@ -56,9 +56,9 @@ impl FormatNodeRule for FormatHtmlSelfClosingElement {
// To resolve this, these tokens either need to be passed to or deferred to sibling text elements when
// whitespace sensitivity would require it.
if slash_token.is_some() {
- write!(f, [slash_token.format()])?;
+ write!(f, [if_group_fits_on_line(&space()), slash_token.format()])?;
} else {
- write!(f, [token("/")])?;
+ write!(f, [if_group_fits_on_line(&space()), token("/")])?;
}
}
// We remove the slash only from void elements
@@ -67,6 +67,10 @@ impl FormatNodeRule for FormatHtmlSelfClosingElement {
write!(f, [format_removed(slash_token)])?;
}
} else {
+ if slash_token.is_some() {
+ // only add a space before the slash if it exists.
+ write!(f, [space()])?;
+ }
write!(f, [slash_token.format()])?;
}
diff --git a/crates/biome_html_formatter/tests/specs/html/component-frameworks/astro-component-casing.astro.snap b/crates/biome_html_formatter/tests/specs/html/component-frameworks/astro-component-casing.astro.snap
index 7b69b59a43b4..0b398e097ef0 100644
--- a/crates/biome_html_formatter/tests/specs/html/component-frameworks/astro-component-casing.astro.snap
+++ b/crates/biome_html_formatter/tests/specs/html/component-frameworks/astro-component-casing.astro.snap
@@ -42,8 +42,8 @@ import Button from './Button.astro';
import TextInput from './TextInput.astro';
---
-
-
+
+
```
diff --git a/crates/biome_html_formatter/tests/specs/html/component-frameworks/large-self-closing.svelte b/crates/biome_html_formatter/tests/specs/html/component-frameworks/large-self-closing.svelte
new file mode 100644
index 000000000000..b7a5bf30a9cb
--- /dev/null
+++ b/crates/biome_html_formatter/tests/specs/html/component-frameworks/large-self-closing.svelte
@@ -0,0 +1,6 @@
+
diff --git a/crates/biome_html_formatter/tests/specs/html/component-frameworks/large-self-closing.svelte.snap b/crates/biome_html_formatter/tests/specs/html/component-frameworks/large-self-closing.svelte.snap
new file mode 100644
index 000000000000..4255bbd38b12
--- /dev/null
+++ b/crates/biome_html_formatter/tests/specs/html/component-frameworks/large-self-closing.svelte.snap
@@ -0,0 +1,43 @@
+---
+source: crates/biome_formatter_test/src/snapshot_builder.rs
+info: component-frameworks/large-self-closing.svelte
+---
+# Input
+
+```svelte
+
+
+```
+
+
+=============================
+
+# Outputs
+
+## Output 1
+
+-----
+Indent style: Tab
+Indent width: 2
+Line ending: LF
+Line width: 80
+Attribute Position: Auto
+Bracket same line: false
+Whitespace sensitivity: css
+Indent script and style: false
+Self close void elements: never
+-----
+
+```svelte
+
+```
diff --git a/crates/biome_html_formatter/tests/specs/html/component-frameworks/svelte-component-casing.svelte.snap b/crates/biome_html_formatter/tests/specs/html/component-frameworks/svelte-component-casing.svelte.snap
index 00e178b7cea3..e5c3b7d8549e 100644
--- a/crates/biome_html_formatter/tests/specs/html/component-frameworks/svelte-component-casing.svelte.snap
+++ b/crates/biome_html_formatter/tests/specs/html/component-frameworks/svelte-component-casing.svelte.snap
@@ -46,9 +46,9 @@ Self close void elements: never
import Select from './Select.svelte';
-
-
-
+
+
+