Skip to main content
Basic Svelte
Introduction
Reactivity
Props
Logic
Events
Bindings
Classes and styles
Actions
Transitions
Advanced Svelte
Advanced reactivity
Reusing content
Motion
Advanced bindings
Advanced transitions
Context API
Special elements
<script module>
Next steps
Basic SvelteKit
Introduction
Routing
Loading data
Headers and cookies
Shared modules
Forms
API routes
$app/state
Errors and redirects
Advanced SvelteKit
Hooks
Page options
Link options
Advanced routing
Advanced loading
Environment variables
Conclusion

It would be impractical to put your entire app in a single component. Instead, we can import components from other files and include them in our markup.

Add a <script> tag to the top of App.svelte that imports Nested.svelte...

App
<script>
	import Nested from './Nested.svelte';
</script>
<script lang="ts">
	import Nested from './Nested.svelte';
</script>

...and include a <Nested /> component:

App
<p>This is a paragraph.</p>
<Nested />

Notice that even though Nested.svelte has a <p> element, the styles from App.svelte don’t leak in.

Component names are capitalised, to distinguish them from HTML elements.

Edit this page on GitHub

previous next
1
2
3
4
5
6
7
8
9
10
<p>This is a paragraph.</p>
 
<style>
	p {
		color: goldenrod;
		font-family: 'Comic Sans MS', cursive;
		font-size: 2em;
	}
</style>