<svelte:element> element lets you render an element that is unknown at author time, for example because it comes from a CMS. Any properties and event listeners present will be applied to the element.
Attributes
The tag name of the HTML element to render. Must be a valid DOM element tag.If
this has a nullish value, the element and its children will not be rendered.Invalid values like #text or svelte:head will not work.The XML namespace for the element. Use this to explicitly set the namespace when Svelte cannot infer it from context.Common values:
"http://www.w3.org/2000/svg"for SVG elements"http://www.w3.org/1998/Math/MathML"for MathML elements
Usage
Basic dynamic element
Dynamic heading levels
With attributes and event listeners
Binding to the element
The only supported binding isbind:this, since Svelte’s built-in bindings do not work with generic elements:
Conditional rendering
Whenthis is null or undefined, nothing is rendered:
Explicit namespace
Svelte tries its best to infer the correct namespace from the element’s surroundings, but it’s not always possible. You can make it explicit with anxmlns attribute: