Overview - Script, markup, and style sections
What is it?
In Svelte, components are made up of three main parts: script, markup, and style sections. The script section holds the JavaScript code that controls the component's behavior. The markup section contains the HTML-like code that defines what the component shows on the screen. The style section includes CSS that styles the component's appearance. These sections work together to build interactive and styled user interfaces.
Why it matters
Without separating script, markup, and style, building user interfaces would be messy and hard to manage. This clear division helps developers organize code so it’s easier to read, update, and reuse. It also allows Svelte to optimize the app by compiling these parts efficiently, making apps faster and smaller. Without this, web apps would be slower and harder to maintain.
Where it fits
Before learning this, you should know basic HTML, CSS, and JavaScript. After mastering these sections, you can learn about Svelte’s advanced features like reactive statements, stores, and component lifecycle. This topic is a foundation for building any Svelte app.