# Table of Contents - [Introduction • Docs • Svelte](#introduction-docs-svelte) - [Creating a project • Docs • Svelte](#creating-a-project-docs-svelte) - [Project structure • Docs • Svelte](#project-structure-docs-svelte) - [Web standards • Docs • Svelte](#web-standards-docs-svelte) - [Adapters • Docs • Svelte](#adapters-docs-svelte) - [Page options • Docs • Svelte](#page-options-docs-svelte) - [State management • Docs • Svelte](#state-management-docs-svelte) - [Zero-config deployments • Docs • Svelte](#zero-config-deployments-docs-svelte) - [Building your app • Docs • Svelte](#building-your-app-docs-svelte) - [Routing • Docs • Svelte](#routing-docs-svelte) - [Static site generation • Docs • Svelte](#static-site-generation-docs-svelte) - [Single-page apps • Docs • Svelte](#single-page-apps-docs-svelte) - [Cloudflare Pages • Docs • Svelte](#cloudflare-pages-docs-svelte) --- # Introduction • Docs • Svelte [Skip to main content](#main) Before we begin[](#Before-we-begin) ------------------------------------ > If you’re new to Svelte or SvelteKit we recommend checking out the [interactive tutorial](/tutorial/kit) > . > > If you get stuck, reach out for help in the [Discord chatroom](/chat) > . What is SvelteKit?[](#What-is-SvelteKit) ----------------------------------------- SvelteKit is a framework for rapidly developing robust, performant web applications using [Svelte](../svelte) . If you’re coming from React, SvelteKit is similar to Next. If you’re coming from Vue, SvelteKit is similar to Nuxt. To learn more about the kinds of applications you can build with SvelteKit, see the [FAQ](faq#What-can-I-make-with-SvelteKit) . What is Svelte?[](#What-is-Svelte) ----------------------------------- In short, Svelte is a way of writing user interface components — like a navigation bar, comment section, or contact form — that users see and interact with in their browsers. The Svelte compiler converts your components to JavaScript that can be run to render the HTML for the page and to CSS that styles the page. You don’t need to know Svelte to understand the rest of this guide, but it will help. If you’d like to learn more, check out [the Svelte tutorial](/tutorial) . SvelteKit vs Svelte[](#SvelteKit-vs-Svelte) -------------------------------------------- Svelte renders UI components. You can compose these components and render an entire page with just Svelte, but you need more than just Svelte to write an entire app. SvelteKit helps you build web apps while following modern best practices and providing solutions to common development challenges. It offers everything from basic functionalities — like a [router](glossary#Routing) that updates your UI when a link is clicked — to more advanced capabilities. Its extensive list of features includes [build optimizations](https://vitejs.dev/guide/features.html#build-optimizations) to load only the minimal required code; [offline support](service-workers) ; [preloading](link-options#data-sveltekit-preload-data) pages before user navigation; [configurable rendering](page-options) to handle different parts of your app on the server via [SSR](glossary#SSR) , in the browser through [client-side rendering](glossary#CSR) , or at build-time with [prerendering](glossary#Prerendering) ; [image optimization](images) ; and much more. Building an app with all the modern best practices is fiendishly complicated, but SvelteKit does all the boring stuff for you so that you can get on with the creative part. It reflects changes to your code in the browser instantly to provide a lightning-fast and feature-rich development experience by leveraging [Vite](https://vitejs.dev/) with a [Svelte plugin](https://github.com/sveltejs/vite-plugin-svelte) to do [Hot Module Replacement (HMR)](https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/config.md#hot) . [Edit this page on GitHub](https://github.com/sveltejs/kit/edit/main/documentation/docs/10-getting-started/10-introduction.md) previous next [Creating a project](/docs/kit/creating-a-project) --- # Creating a project • Docs • Svelte [Skip to main content](#main) The easiest way to start building a SvelteKit app is to run `npx sv create`: npx sv create my-app cd my-app npm install npm run dev The first command will scaffold a new project in the `my-app` directory asking you if you’d like to set up some basic tooling such as TypeScript. See [integrations](./integrations) for pointers on setting up additional tooling. The subsequent commands will then install its dependencies and start a server on [localhost:5173](http://localhost:5173) . There are two basic concepts: * Each page of your app is a [Svelte](../svelte) component * You create pages by adding files to the `src/routes` directory of your project. These will be server-rendered so that a user’s first visit to your app is as fast as possible, then a client-side app takes over Try editing the files to get a feel for how everything works. Editor setup[](#Editor-setup) ------------------------------ We recommend using [Visual Studio Code (aka VS Code)](https://code.visualstudio.com/download) with [the Svelte extension](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode) , but [support also exists for numerous other editors](https://sveltesociety.dev/resources#editor-support) . [Edit this page on GitHub](https://github.com/sveltejs/kit/edit/main/documentation/docs/10-getting-started/20-creating-a-project.md) previous next [Introduction](/docs/kit/introduction) [Project structure](/docs/kit/project-structure) --- # Project structure • Docs • Svelte [Skip to main content](#main) A typical SvelteKit project looks like this: my-project/ ├ src/ │ ├ lib/ │ │ ├ server/ │ │ │ └ [your server-only lib files] │ │ └ [your lib files] │ ├ params/ │ │ └ [your param matchers] │ ├ routes/ │ │ └ [your routes] │ ├ app.html │ ├ error.html │ ├ hooks.client.js │ ├ hooks.server.js │ └ service-worker.js ├ static/ │ └ [your static assets] ├ tests/ │ └ [your tests] ├ package.json ├ svelte.config.js ├ tsconfig.json └ vite.config.js You’ll also find common files like `.gitignore` and `.npmrc` (and `.prettierrc` and `eslint.config.js` and so on, if you chose those options when running `npx sv create`). Project files[](#Project-files) -------------------------------- ### src[](#Project-files-src) The `src` directory contains the meat of your project. Everything except `src/routes` and `src/app.html` is optional. * `lib` contains your library code (utilities and components), which can be imported via the [`$lib`]($lib) alias, or packaged up for distribution using [`svelte-package`](packaging) * `server` contains your server-only library code. It can be imported by using the [`$lib/server`](server-only-modules) alias. SvelteKit will prevent you from importing these in client code. * `params` contains any [param matchers](advanced-routing#Matching) your app needs * `routes` contains the [routes](routing) of your application. You can also colocate other components that are only used within a single route here * `app.html` is your page template — an HTML document containing the following placeholders: * `%sveltekit.head%` — `` and ` src/routes/user/+page
Welcome {user().name}
Welcome {user().name}
> We’re passing a function into `setContext` to keep reactivity across boundaries. Read more about it [here](/docs/svelte/$state#Passing-state-into-functions) > Legacy mode > > You also use stores from `svelte/store` for this, but when using Svelte 5 it is recommended to make use of universal reactivity instead. Updating the value of context-based state in deeper-level pages or components while the page is being rendered via SSR will not affect the value in the parent component because it has already been rendered by the time the state value is updated. In contrast, on the client (when CSR is enabled, which is the default) the value will be propagated and components, pages, and layouts higher in the hierarchy will react to the new value. Therefore, to avoid values ‘flashing’ during state updates during hydration, it is generally recommended to pass state down into components rather than up. If you’re not using SSR (and can guarantee that you won’t need to use SSR in future) then you can safely keep state in a shared module, without using the context API. Component and page state is preserved[](#Component-and-page-state-is-preserved) -------------------------------------------------------------------------------- When you navigate around your application, SvelteKit reuses existing layout and page components. For example, if you have a route like this... src/routes/blog/\[slug\]/+pageReading time: {Math.round(estimatedReadingTime)} minutes
Reading time: {Math.round(estimatedReadingTime)} minutes