HTML Tags
Svelte distinguishes between regular HTML elements and components based on naming:- Lowercase tags like
<div>denote regular HTML elements - Capitalized tags or dot notation like
<Widget>or<my.stuff>indicate components
Element Attributes
Attributes work like their HTML counterparts, but with powerful enhancements for dynamic values.Static Attributes
Dynamic Attributes
Attribute values can contain JavaScript expressions:Boolean and Nullish Attributes
Other Attributes
Included unless nullish (
null or undefined)Attribute Shorthand
When attribute name and value match, use shorthand syntax:Component Props
Values passed to components are called props (not attributes):Spread Attributes
Pass multiple attributes or props at once using spread syntax:Text Expressions
Embed JavaScript expressions in text using curly braces:Expression Behavior
nullorundefinedvalues are omitted- All other values are coerced to strings
- Regular expressions need parentheses:
Rendering HTML
Expressions are escaped by default. To render HTML, use the{@html} tag:
Comments
Use HTML comments inside components:Disabling Warnings
Comments starting withsvelte-ignore disable warnings for the next markup block:
Component Documentation
Add@component comments to show documentation when hovering over component usage: