--- title: Component fundamentals --- - script (module) / template / style (rough overview) - `$props` / `$state` (in the context of components) Components are the building blocks of Svelte applications. They are written into `.svelte` files, using a superset of HTML. All three sections — script, styles and markup — are optional. ```svelte ``` ## ` ``` You can specify a fallback value for a prop. It will be used if the component's consumer doesn't specify the prop on the component when instantiating the component, or if the passed value is `undefined` at some point. ```svelte ``` To get all properties, use rest syntax: ```svelte ``` You can use reserved words as prop names. ```svelte ``` If you're using TypeScript, you can declare the prop types: ```svelte ``` If you're using JavaScript, you can declare the prop types using JSDoc: ```svelte ``` If you export a `const`, `class` or `function`, it is readonly from outside the component. ```svelte ``` Readonly props can be accessed as properties on the element, tied to the component using [`bind:this` syntax](bindings#bind:this). ### Reactive variables To change component state and trigger a re-render, just assign to a locally declared variable that was declared using the `$state` rune. Update expressions (`count += 1`) and property assignments (`obj.x = y`) have the same effect. ```svelte ``` Svelte's ` ``` If you'd like to react to changes to a prop, use the `$derived` or `$effect` runes instead. ```svelte ``` For more information on reactivity, read the documentation around runes. ## ` ``` ## ` ``` For more information regarding styling, read the documentation around [styles and classes](styles-and-classes).