Interpolation: {expression}
Embed JavaScript expressions directly into Svelte HTML templates.
Interpolation: {expression} is a free Sveltejs Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Sveltejs Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Curly Brace Syntax
Embed any JavaScript expression in markup by wrapping it in curly braces.
<p>Hello {name}!</p>Math and Strings
Expressions can be more than variable names. Do math, string concatenation, or method calls.
<p>{count + 1} items, formatted: {name.toUpperCase()}</p>Attribute Interpolation
Use the same syntax inside HTML attributes.
<img src={imageUrl} alt={altText} />Shorthand Attributes
If the attribute and variable have the same name, use the shorthand form.
<img {src} {alt} />Boolean Attributes
For boolean attributes like disabled, pass any truthy value. Use {flag} directly.
<button disabled={isLoading}>Save</button>Spread Attributes
Spread an object of attributes onto an element with the {...obj} syntax.
<input {...inputProps} />Text vs HTML
By default interpolation escapes HTML for safety. Use {@html ...} only with trusted content.
<div>{@html trustedHtml}</div>Conditional Expressions
Ternaries work inside braces for simple branching.
<p>Status: {isOnline ? "online" : "offline"}</p>Null and Undefined
If your expression evaluates to null or undefined, Svelte renders nothing.
Function Calls
Call functions inside braces, but keep them cheap. They re-run on every reactive update.
<p>Total: {formatCurrency(amount)}</p>Comments
Use ordinary HTML comments. They do not appear in the rendered output.
<!-- This is a comment -->Quick Check
How do you safely embed text?
Recap
Single curly braces interpolate any expression in text and attributes, with shorthand and spread for ergonomics.
Frequently asked questions
Is the “Interpolation: {expression}” lesson free?
Yes — the full text of “Interpolation: {expression}” is free to read here on the web, and the Sveltejs Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Sveltejs Academy course, upgrade to CoddyKit PRO.
What will I learn in “Interpolation: {expression}”?
Embed JavaScript expressions directly into Svelte HTML templates. You practise Sveltejs Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Sveltejs Academy?
No prior experience is required. Sveltejs Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Interpolation: {expression}” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Sveltejs Academy lesson?
Yes. Every Sveltejs Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- The script template style Structure
- Reactive Variables with let
- Interpolation: {expression}
- Computed Values: $: reactive declarations