Component Structure in Svelte

From the Svelte cheat sheet ยท Setup & Basics ยท verified Jul 2026

Component Structure

Basic Svelte component anatomy

javascript
<!-- MyComponent.svelte -->
<script>
  let message = 'Hello Svelte';
</script>

<h1>{message}</h1>

<style>
  h1 { color: #ff3e00; }
</style>
๐ŸŽจ Styles are scoped to component by default
๐Ÿ“ No JSX - write regular HTML with enhancements
๐Ÿ”’ TypeScript support with lang="ts" attribute
โšก Components compile to efficient JavaScript

More Svelte tasks

Back to the full Svelte cheat sheet