0
0
Svelteframework~10 mins

Script, markup, and style sections in Svelte - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Script, markup, and style sections
Start Svelte File
Parse <script> Section
Parse Markup Section
Parse <style> Section
Combine All Sections
Render Component in Browser
Svelte reads the script first to get logic, then the markup for structure, then styles for look, and finally combines all to show the component.
Execution Sample
Svelte
<script>
  let count = 0;
</script>

<button on:click={() => count++}>
  Clicked {count} times
</button>

<style>
  button { color: blue; }
</style>
A simple Svelte component with a script for logic, markup for button, and style for button color.
Execution Table
StepSection ParsedActionState/ValueEffect
1<script>Declare variable countcount = 0Logic ready for use in markup
2MarkupCreate button elementbutton element createdButton appears on page
3MarkupBind click event to increment countclick event attachedButton click updates count
4MarkupDisplay count inside buttoncount displayed as 0User sees 'Clicked 0 times'
5<style>Apply CSS to buttonbutton color set to blueButton text color is blue
6RenderCombine all sectionsComponent readyInteractive blue button shown
7User clicks buttoncount incrementscount = 1Button text updates to 'Clicked 1 times'
💡 User stops clicking; component remains interactive with updated count
Variable Tracker
VariableStartAfter Click 1After Click 2Final
count0122
Key Moments - 3 Insights
Why does the count variable update the button text automatically?
Because Svelte tracks reactive variables declared in <script> and updates the markup when they change, as shown in execution_table step 7.
What happens if the <style> section is missing?
The component still works but the button will have default styles, no blue color applied (see execution_table step 5).
Can the markup access variables declared in <script>?
Yes, markup uses variables from <script> directly, like count in the button text (execution_table step 4).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the value of count after the first click?
A2
B0
C1
Dundefined
💡 Hint
Check execution_table row 7 where count increments after click
At which step is the button's color set to blue?
AStep 5
BStep 2
CStep 4
DStep 7
💡 Hint
Look at execution_table step describing