Skip to content

Components & Templating

In React every component is a function that returns JSX. In Svelte every component is a .svelte file that combines script, markup, and styles in a single, familiar HTML-like format. No JSX, no className, no separate CSS file needed.

This module walks you through the core building blocks:

LessonConcept
This page.svelte file structure vs React function components
Props$props() rune vs React props destructuring
Template blocks{#if}, {#each}, {#await} vs JSX ternaries and .map()
Eventsonclick={fn} vs onClick={fn}
Snippets & children{#snippet} / {@render} vs React children
Bindingsbind:value vs controlled inputs
StylesScoped <style> vs CSS Modules / CSS-in-JS
flowchart TB
  file([".svelte file"])
  file --> script["&lt;script&gt; — component logic (JS/TS, runes)"]
  file --> markup["markup — HTML template (no JSX, no return)"]
  file --> style["&lt;style&gt; — scoped CSS (auto-scoped to this component)"]
The three sections of a .svelte file

Only the markup section is required. <script> and <style> are optional.

React
// Greeting.jsx
function Greeting({ name }) {
return <h1>Hello, {name}!</h1>;
}
export default Greeting;
Svelte
<!-- Greeting.svelte -->
<script>
let { name } = $props();
</script>
<h1>Hello, {name}!</h1>

The markup in a .svelte file is the entire file body — no return statement, no parentheses, no JSX pragma.

Where does component logic live in a Svelte file?
How are styles scoped in a Svelte component?
Which Svelte 5 rune reads incoming props?