Skip to main content
Create new
Introduction
Reactivity
Props
Logic
Events
Bindings
Lifecycle
Stores
Motion
Transitions
Animations
Easing
SVG
Actions
Classes
Component composition
Context API
Special elements
Module context
Debugging
7GUIs
Miscellaneous
App.svelte
<script>
export let name = 'world';
</script>

<main>
<h1>Hello {name}!</h1>
<p>Visit the <a href="https://svelte.dev/tutorial">Svelte tutorial</a> to learn how to build Svelte apps.</p>
</main>

<style>
main {
text-align: center;
padding: 1em;
max-width: 240px;
margin: 0 auto;
}

h1 {
color: #ff3e00;
text-transform: uppercase;
font-size: 4em;
font-weight: 100;
}

@media (min-width: 640px) {
main {
max-width: none;
}
}
</style>
import 'svelte/internal/disclose-version';
import 'svelte/internal/flags/legacy';
import * as $ from 'svelte/internal/client';

var root = $.template(`<main class="svelte-1tky8bj"><h1 class="svelte-1tky8bj"> </h1> <p>Visit the <a href="https://svelte.dev/tutorial">Svelte tutorial</a> to learn how to build Svelte apps.</p></main>`);

export default function App($$anchor, $$props) {
let name = $.prop($$props, 'name', 8, 'world');
var main = root();
var h1 = $.child(main);
var text = $.child(h1);

$.reset(h1);
$.next(2);
$.reset(main);
$.template_effect(() => $.set_text(text, `Hello ${name() ?? ''}!`));
$.append($$anchor, main);
}
result = svelte.compile(source, {
generate: ,
});

main.svelte-1tky8bj {
text-align: center;
padding: 1em;
max-width: 240px;
margin: 0 auto;
}

h1.svelte-1tky8bj {
color: #ff3e00;
text-transform: uppercase;
font-size: 4em;
font-weight: 100;
}

@media (min-width: 640px) {
main.svelte-1tky8bj {
max-width: none;
}
}

		
			
				
  • Root {
    • css: StyleSheet {...}
      • type: "StyleSheet"
      • start: 199
      • end: 463
      • attributes: []
      • children: [...] (3)
        • Rule {...}
          • type: "Rule"
          • prelude: SelectorList {...}
            • type: "SelectorList"
            • start: 208
            • end: 212
            • children: [...] (1)
              • ComplexSelector {...}
                • type: "ComplexSelector"
                • start: 208
                • end: 212
                • children: [...] (1)
                  • RelativeSelector {...}
                    • type: "RelativeSelector"
                    • combinator: null
                    • selectors: [...] (1)
                      • TypeSelector {...}
                        • type: "TypeSelector"
                        • name: "main"
                        • start: 208
                        • end: 212
                        }
                      ]
                    • start: 208
                    • end: 212
                    }
                  ]
                }
              ]
            }
          • block: Block {...}
            • type: "Block"
            • start: 213
            • end: 293
            • children: [...] (4)
              • Declaration {...}
                • type: "Declaration"
                • start: 217
                • end: 235
                • property: "text-align"
                • value: "center"
                }
              • Declaration {...}
                • type: "Declaration"
                • start: 239
                • end: 251
                • property: "padding"
                • value: "1em"
                }
              • Declaration {...}
                • type: "Declaration"
                • start: 255
                • end: 271
                • property: "max-width"
                • value: "240px"
                }
              • Declaration {...}
                • type: "Declaration"
                • start: 275
                • end: 289
                • property: "margin"
                • value: "0 auto"
                }
              ]
            }
          • start: 208
          • end: 293
          }
        • Rule {...}
          • type: "Rule"
          • prelude: SelectorList {...}
            • type: "SelectorList"
            • start: 296
            • end: 298
            • children: [...] (1)
              • ComplexSelector {...}
                • type: "ComplexSelector"
                • start: 296
                • end: 298
                • children: [...] (1)
                  • RelativeSelector {...}
                    • type: "RelativeSelector"
                    • combinator: null
                    • selectors: [...] (1)
                      • TypeSelector {...}
                        • type: "TypeSelector"
                        • name: "h1"
                        • start: 296
                        • end: 298
                        }
                      ]
                    • start: 296
                    • end: 298
                    }
                  ]
                }
              ]
            }
          • block: Block {...}
            • type: "Block"
            • start: 299
            • end: 388
            • children: [...] (4)
              • Declaration {...}
                • type: "Declaration"
                • start: 303
                • end: 317
                • property: "color"
                • value: "#ff3e00"
                }
              • Declaration {...}
                • type: "Declaration"
                • start: 321
                • end: 346
                • property: "text-transform"
                • value: "uppercase"
                }
              • Declaration {...}
                • type: "Declaration"
                • start: 350
                • end: 364
                • property: "font-size"
                • value: "4em"
                }
              • Declaration {...}
                • type: "Declaration"
                • start: 368
                • end: 384
                • property: "font-weight"
                • value: "100"
                }
              ]
            }
          • start: 296
          • end: 388
          }
        • Atrule {...}
          • type: "Atrule"
          • start: 391
          • end: 454
          • name: "media"
          • prelude: "(min-width: 640px)"
          • block: Block {...}
            • type: "Block"
            • start: 417
            • end: 454
            • children: [...] (1)
              • Rule {...}
                • type: "Rule"
                • prelude: SelectorList {...}
                  • type: "SelectorList"
                  • start: 421
                  • end: 425
                  • children: [...] (1)
                    • ComplexSelector {...}
                      • type: "ComplexSelector"
                      • start: 421
                      • end: 425
                      • children: [...] (1)
                        • RelativeSelector {...}
                          • type: "RelativeSelector"
                          • combinator: null
                          • selectors: [...] (1)
                            • TypeSelector {...}
                              • type: "TypeSelector"
                              • name: "main"
                              • start: 421
                              • end: 425
                              }
                            ]
                          • start: 421
                          • end: 425
                          }
                        ]
                      }
                    ]
                  }
                • block: Block {...}
                  • type: "Block"
                  • start: 426
                  • end: 451
                  • children: [...] (1)
                    • Declaration {...}
                      • type: "Declaration"
                      • start: 431
                      • end: 446
                      • property: "max-width"
                      • value: "none"
                      }
                    ]
                  }
                • start: 421
                • end: 451
                }
              ]
            }
          }
        ]
      • content: {...}
        • start: 206
        • end: 455
        • styles: "\n\tmain {\n\t\ttext-align: center;\n\t\tpadding: 1em;\n\t\tmax-width: 240px;\n\t\tmargin: 0 auto;\n\t}\n\n\th1 {\n\t\tcolor: #ff3e00;\n\t\ttext-transform: uppercase;\n\t\tfont-size: 4em;\n\t\tfont-weight: 100;\n\t}\n\n\t@media (min-width: 640px) {\n\t\tmain {\n\t\t\tmax-width: none;\n\t\t}\n\t}\n"
        • comment: null
        }
      }
    • js: []
    • start: 48
    • end: 197
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (3)
        • Text {...}
          • type: "Text"
          • start: 46
          • end: 48
          • raw: "\n\n"
          • data: "\n\n"
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 48
          • end: 197
          • name: "main"
          • attributes: [...] (1)
            • Attribute {...}
              • type: "Attribute"
              • start: -1
              • end: -1
              • name: "class"
              • value: [...] (1)
                • Text {...}
                  • type: "Text"
                  • data: ""
                  • raw: ""
                  • start: -1
                  • end: -1
                  }
                ]
              }
            ]
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (5)
              • Text {...}
                • type: "Text"
                • start: 54
                • end: 56
                • raw: "\n\t"
                • data: "\n\t"
                }
              • RegularElement {...}
                • type: "RegularElement"
                • start: 56
                • end: 78
                • name: "h1"
                • attributes: [...] (1)
                  • Attribute {...}
                    • type: "Attribute"
                    • start: -1
                    • end: -1
                    • name: "class"
                    • value: [...] (1)
                      • Text {...}
                        • type: "Text"
                        • data: ""
                        • raw: ""
                        • start: -1
                        • end: -1
                        }
                      ]
                    }
                  ]
                • fragment: Fragment {...}
                  • type: "Fragment"
                  • nodes: [...] (3)
                    • Text {...}
                      • type: "Text"
                      • start: 60
                      • end: 66
                      • raw: "Hello "
                      • data: "Hello "
                      }
                    • ExpressionTag {...}
                      • type: "ExpressionTag"
                      • start: 66
                      • end: 72
                      • expression: Identifier {...}
                        • type: "Identifier"
                        • start: 67
                        • end: 71
                        • loc: {...}
                          • start: {...}
                            • line: 6
                            • column: 12
                            }
                          • end: {...}
                            • line: 6
                            • column: 16
                            }
                          }
                        • name: "name"
                        }
                      }
                    • Text {...}
                      • type: "Text"
                      • start: 72
                      • end: 73
                      • raw: "!"
                      • data: "!"
                      }
                    ]
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 78
                • end: 80
                • raw: " "
                • data: " "
                }
              • RegularElement {...}
                • type: "RegularElement"
                • start: 80
                • end: 189
                • name: "p"
                • attributes: []
                • fragment: Fragment {...}
                  • type: "Fragment"
                  • nodes: [...] (3)
                    • Text {...}
                      • type: "Text"
                      • start: 83
                      • end: 93
                      • raw: "Visit the "
                      • data: "Visit the "
                      }
                    • RegularElement {...}
                      • type: "RegularElement"
                      • start: 93
                      • end: 150
                      • name: "a"
                      • attributes: [...] (1)
                        • Attribute {...}
                          • type: "Attribute"
                          • start: 96
                          • end: 130
                          • name: "href"
                          • value: [...] (1)
                            • Text {...}
                              • start: 102
                              • end: 129
                              • type: "Text"
                              • raw: "https://svelte.dev/tutorial"
                              • data: "https://svelte.dev/tutorial"
                              }
                            ]
                          }
                        ]
                      • fragment: Fragment {...}
                        • type: "Fragment"
                        • nodes: [...] (1)
                          • Text {...}
                            • type: "Text"
                            • start: 131
                            • end: 146
                            • raw: "Svelte tutorial"
                            • data: "Svelte tutorial"
                            }
                          ]
                        }
                      }
                    • Text {...}
                      • type: "Text"
                      • start: 150
                      • end: 185
                      • raw: " to learn how to build Svelte apps."
                      • data: " to learn how to build Svelte apps."
                      }
                    ]
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 189
                • end: 190
                • raw: "\n"
                • data: "\n"
                }
              ]
            }
          }
        • Text {...}
          • type: "Text"
          • start: 197
          • end: 199
          • raw: "\n\n"
          • data: "\n\n"
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 46
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 37
        • loc: {...}
          • start: {...}
            • line: 1
            • column: 0
            }
          • end: {...}
            • line: 3
            • column: 0
            }
          }
        • body: [...] (1)
          • ExportNamedDeclaration {...}
            • type: "ExportNamedDeclaration"
            • start: 10
            • end: 36
            • loc: {...}
              • start: {...}
                • line: 2
                • column: 1
                }
              • end: {...}
                • line: 2
                • column: 27
                }
              }
            • declaration: VariableDeclaration {...}
              • type: "VariableDeclaration"
              • start: 17
              • end: 36
              • loc: {...}
                • start: {...}
                  • line: 2
                  • column: 8
                  }
                • end: {...}
                  • line: 2
                  • column: 27
                  }
                }
              • declarations: [...] (1)
                • VariableDeclarator {...}
                  • type: "VariableDeclarator"
                  • start: 21
                  • end: 35
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 12
                      }
                    • end: {...}
                      • line: 2
                      • column: 26
                      }
                    }
                  • id: Identifier {...}
                    • type: "Identifier"
                    • start: 21
                    • end: 25
                    • loc: {...}
                      • start: {...}
                        • line: 2
                        • column: 12
                        }
                      • end: {...}
                        • line: 2
                        • column: 16
                        }
                      }
                    • name: "name"
                    }
                  • init: Literal {...}
                    • type: "Literal"
                    • start: 28
                    • end: 35
                    • loc: {...}
                      • start: {...}
                        • line: 2
                        • column: 19
                        }
                      • end: {...}
                        • line: 2
                        • column: 26
                        }
                      }
                    • value: "world"
                    • raw: "'world'"
                    }
                  }
                ]
              • kind: "let"
              }
            • specifiers: []
            • source: null
            }
          ]
        • sourceType: "module"
        }
      • attributes: []
      }
    }
The AST is not public API and may change at any point in time
MDN Svelte tutorial: 01-getting-started • Playground • Svelte