Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 35 ยท Getting Started

What Is Svelte?

Learn what Svelte is, how a compiler-first framework differs from a runtime library, and what you can build with Svelte 5 and its runes.

Svelte is a framework for building user interfaces. You write components in .svelte files that look like plain HTML with a little extra, and a compiler turns them into small, efficient JavaScript. There is no large runtime that walks a virtual copy of your page; the compiled code updates exactly the parts of the DOM that changed.

This course teaches Svelte 5, the current major version. Its central idea is runes: special $-prefixed markers such as $state and $derived that tell the compiler which values are reactive. If you have seen older Svelte code that relied on $: labels, you will meet that only as a history note.

The Svelte compiler cannot run inside this site's code editors. Real Svelte code is shown in read-only blocks, and every lesson gives you a runnable plain-JavaScript stand-in that explains the idea behind the feature. The stand-ins are honest simplifications, not the real compiler output.

A compiler, not a runtime

Most UI libraries ship a runtime to the browser. That runtime receives a description of the UI after each change, compares it to the previous description, and patches the page. Svelte moves much of that work to build time.

Runtime library

Ships a runtime Library code runs in the browser
Compares trees Finds what changed
Patches the DOM
1 / 2

The compiler reads your component, sees which values are used in the markup, and generates code that touches only those spots when the value changes. That is why Svelte apps are often small and quick, especially on slower phones.

What a component looks like

A Svelte component is a file with up to three parts: a <script> for logic, markup, and an optional <style>.

SVELTE
<script>
  let count = $state(0);
</script>

<button onclick={() => count++}>
  Clicked {count} {count === 1 ? 'time' : 'times'}
</button>

<style>
  button {
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
  }
</style>

Three things stand out:

  • $state(0) declares reactive state. Assigning to count updates the page.
  • puts a JavaScript expression into the markup.
  • The <style> is scoped: it only affects this component's elements.

There is no setCount, no hook rules, and no template language to learn beyond a few curly-brace blocks.

The idea behind reactivity

Svelte tracks which pieces of the page read a value. When the value changes, only those readers rerun. You can build a tiny version of that idea yourself in plain JavaScript. This is a teaching stand-in, not what Svelte generates, but the principle (readers register themselves; writes notify them) is the same one you will use all course.

JS A tiny reactive value (stand-in)

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The effect printed three lines: once at the start, then once per set. Svelte does the equivalent registration for you at compile time, with far less ceremony.

What Svelte is good at

  • Interactive pages and apps: dashboards, forms, editors, widgets.
  • Small embeds: components that compile to little code suit widgets dropped into other sites.
  • Full applications with SvelteKit: routing, server rendering, data loading and deployment adapters (covered in the SvelteKit chapter).
  • Teaching and prototyping: the syntax stays close to HTML, CSS and JavaScript.

It is less of a fit when your team already has a large investment in another framework's ecosystem, or when you need a particular third-party component library that only exists elsewhere.

Svelte next to other tools

If you know React or Vue, the concepts map across: components, props, events, conditional and list rendering. The differences are mostly in how updates are discovered. React reruns your component function and diffs; Vue wraps data in reactive proxies and uses a virtual DOM; Svelte compiles dependencies into direct updates. You do not need any of them to follow this course, only basic HTML, CSS and JavaScript.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the main thing that makes Svelte different from a runtime-heavy UI library?

    Svelte moves work to build time. The compiler works out what depends on what, so the browser needs less code.
  2. 2. Which line declares reactive state in Svelte 5?

    Runes such as $state mark reactive values. $: is the older Svelte 3/4 style.
  3. 3. What does the scoped <style> block in a component do?

    Svelte adds a unique class to the component's elements so its styles do not leak out.
  4. 4. Why does this site show Svelte code in read-only blocks?

    The editors run HTML/JS, Python, SQL and server languages, but they do not include the Svelte compiler.

Summary

  • Svelte is a compiler-first UI framework; components live in .svelte files.
  • Svelte 5 marks reactivity with runes such as $state, $derived and $effect.
  • The compiler tracks which values the markup reads and updates only those places.
  • Styles in a component are scoped by default.
  • In this course, real Svelte is read-only and runnable stand-ins show the idea.

Next: Setting Up a Svelte Project