<a> elements are used to navigate between routes. You can customize their behavior with data-sveltekit-* attributes to make your app feel faster.
Overview
SvelteKit intercepts clicks on<a> elements whose href is owned by your app and handles navigation without a full page reload. You can customize this with data attributes.
These options also apply to
<form> elements with method="GET".data-sveltekit-preload-data
Before the browser registers a click, SvelteKit can detect hovers and touch events to get a head start on importing code and fetching data.hover
Preloading starts when mouse hovers over link. On mobile, begins on
touchstart.tap
Preloading starts on
touchstart or mousedown event.Default configuration
The default template applies hover preloading to all links:src/app.html
Custom preloading
data-sveltekit-preload-code
Preload just the code for a route without fetching data.viewport and eager only apply to links present in the DOM immediately after navigation. Links added later (in {#if ...} blocks) won’t preload until triggered by hover or tap.data-sveltekit-reload
Force a full-page navigation instead of client-side routing:When to use full-page navigation
When to use full-page navigation
Links with
rel="external" receive the same treatment and are ignored during prerendering.data-sveltekit-replacestate
Replace the current history entry instead of creating a new one:data-sveltekit-keepfocus
Keep focus on the current element after navigation:data-sveltekit-noscroll
Prevent scrolling to the top after navigation:Default scroll behavior
Default scroll behavior
By default, SvelteKit:
- Scrolls to
0,0(top-left) after navigation - Scrolls to element with matching ID if link includes
#hash - Preserves scroll position on back/forward navigation
Combining options
You can use multiple attributes together:Inheritance and overriding
Attributes can be applied to parent elements and overridden on children:Conditional attributes
Apply attributes conditionally in Svelte:Performance considerations
Preload data on hover
Preload data on hover
Pros: Faster perceived navigation (200-300ms head start)Cons: Can cause unnecessary requests if users don’t clickBest for: Most content pages with stable data
Preload data on tap
Preload data on tap
Pros: Only loads when user shows clear intentCons: Slightly less head start (only 50-100ms)Best for: Pages with rapidly changing data or expensive queries
Preload code only
Preload code only
Pros: Minimal bandwidth, code is cacheableCons: Still need to fetch data on navigationBest for: Pages where data must be fresh
No preloading
No preloading
Pros: No wasted requestsCons: Slower navigationBest for: Auth-protected routes or rate-limited APIs
Programmatic preloading
Preload routes in your JavaScript code:API Reference
View the complete
$app/navigation API