diff --git a/.changeset/real-onions-confess.md b/.changeset/real-onions-confess.md
new file mode 100644
index 0000000000..5f11b225ad
--- /dev/null
+++ b/.changeset/real-onions-confess.md
@@ -0,0 +1,5 @@
+---
+'svelte': patch
+---
+
+fix: inherit correct namespace for `
` elements
diff --git a/packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js b/packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js
index 9a891c0c49..03dfaebcb7 100644
--- a/packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js
+++ b/packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js
@@ -90,8 +90,11 @@ export function RegularElement(node, context) {
if (is_svg(node.name)) {
return true;
}
- if (node.name === 'a') {
- for (let i = context.path.length - 1; i >= 0; i--) {
+
+ if (node.name === 'a' || node.name === 'title') {
+ let i = context.path.length;
+
+ while (i--) {
const ancestor = context.path[i];
if (ancestor.type === 'RegularElement') {
return ancestor.metadata.svg;
diff --git a/packages/svelte/tests/runtime-runes/samples/svg-namespace-if-block-3/_config.js b/packages/svelte/tests/runtime-runes/samples/svg-namespace-if-block-3/_config.js
new file mode 100644
index 0000000000..7543278b62
--- /dev/null
+++ b/packages/svelte/tests/runtime-runes/samples/svg-namespace-if-block-3/_config.js
@@ -0,0 +1,11 @@
+import { test, ok } from '../../test';
+
+export default test({
+ html: ``,
+ test({ assert, target }) {
+ const title = target.querySelector('title');
+ ok(title);
+
+ assert.equal(title.namespaceURI, 'http://www.w3.org/2000/svg');
+ }
+});
diff --git a/packages/svelte/tests/runtime-runes/samples/svg-namespace-if-block-3/main.svelte b/packages/svelte/tests/runtime-runes/samples/svg-namespace-if-block-3/main.svelte
new file mode 100644
index 0000000000..8be23f8b23
--- /dev/null
+++ b/packages/svelte/tests/runtime-runes/samples/svg-namespace-if-block-3/main.svelte
@@ -0,0 +1,5 @@
+