Passing Props from Parent
Provide values to child component props in the parent template.
Passing Props from Parent is a free Sveltejs Academy lesson on CoddyKit — lesson 2 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.
Import the Child
Use a standard ES import at the top of the parent to bring in the child component.
<script>
import Greeting from "./Greeting.svelte";
</script>Use the Tag
Render the child by writing a tag with its capitalized name.
<Greeting />Pass Static Values
Pass a literal string with quoted attributes.
<Greeting name="Ada" />Pass Dynamic Values
Pass a JS expression by wrapping the value in curly braces.
<Greeting name={userName} />Shorthand Same Name
If the prop and variable share a name, use the shorthand {name}.
<Greeting {name} />Multiple Props
Combine static, dynamic, and shorthand props in any order.
<Card title="Tasks" {items} count={items.length} />Spread Props
Spread an object of props with the {...obj} syntax.
<Card {...cardProps} />Conditional Props
Combine ternaries to provide conditional values.
<Button label={isLoading ? "Saving..." : "Save"} />Boolean Shorthand
Pass a boolean attribute without a value to set it to true.
<Toggle disabled />Functions as Props
You can pass function references as props for callbacks.
<Modal onClose={() => (open = false)} />Object Props
Pass whole objects when many related values travel together.
<UserCard user={currentUser} />Quick Check
How do you pass a variable as a prop?
Recap
Import, use the tag, and pass props with literals, expressions, shorthand, or spread.
Frequently asked questions
Is the “Passing Props from Parent” lesson free?
Yes — the full text of “Passing Props from Parent” 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 “Passing Props from Parent”?
Provide values to child component props in the parent template. 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 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Passing Props from Parent” 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
- Declaring Props with export let
- Passing Props from Parent
- Default Prop Values
- Forwarding Props with $$props and $$restProps