Getting Started
Svelte Installation Guide
Instructions to get your player installed and on-screen using Svelte.
1. Select Framework
Section titled 1. Select Framework2. Select Bundler
Section titled 2. Select Bundler3. Select Provider
Section titled 3. Select Provider4. Select Styling
Section titled 4. Select StylingBe careful of the svelte-preprocess auto-processor when building your own layout as
it will strip away <template>
tags that are used in certain player components. Either specify
the preprocessors you need or change the markupTagName
to something other than “template”.
5. Check Support
Section titled 5. Check SupportEnsure the following browser support table is suitable for your application. We’ve built the library for the modern web; thus, we try to avoid bloated polyfills and outdated environments as much as possible. At the moment, we only support browsers that fully implement the Custom Elements V1 spec.
We support at minimum ~94.18% of users tracked on caniuse.
6. Install Packages
Section titled 6. Install Packages7. Add Types
Section titled 7. Add TypesIf you’re using TypeScript, add the following to your tsconfig
to enable fully-typed
custom elements:
8. Setup Bundler
Section titled 8. Setup BundlerYou can skip this step since you're not using a bundler.
9. Import Library
Section titled 9. Import LibraryThe following imports will include the required CSS styles and variables:
The following imports will register all custom media elements (e.g., <media-player>
) and import global TypeScript types:
10. Player Markup
Section titled 10. Player MarkupThere’s a long-standing hydration bug with Svelte 4 and Custom Elements which has been resolved in Svelte 5. If you’re using Svelte 4, you will need to dynamically import the player or disable SSR:
11. Poster (Optional)
Section titled 11. Poster (Optional)See the Poster component for how to display an image while video content is loading, or until the user hits play. If this is not included, the first frame of the video will be used instead.
12. Playsinline (Optional)
Section titled 12. Playsinline (Optional)The playsinline
property will indicate that video content should be played inline (on mobile only),
rather than launching the video in fullscreen mode on play. In addition, setting this property
will also ensure custom player UI is displayed on iPhone when playing
inline (hidden in fullscreen mode as native controls are forcefully displayed by the browser).
Important to note, we normalize the playing inline behaviour across all mobile browsers. If you
do not set playsinline
, the video will launch in fullscreen on play in all mobile browsers, not
just iOS Safari where the attribute is accepted.
13. Visual Studio (Optional)
Section titled 13. Visual Studio (Optional)This step is optional. VS Code (VSC) provides support for extending the known HTML entities through VSC Custom Data. Once set up, it enables autocomplete suggestions for custom player elements and on-hover information such as documentation and type data.
- Create the VSC settings file at the root of your project directory:
- Add the custom HTML data file path to
html.customData
inside the newly created settings file:
14. Media Icons (Optional)
Section titled 14. Media Icons (Optional)You can skip this step since you're using the Default Layout.
This step is optional. Media Icons is a collection of icons we’ve designed at Vidstack to help with building audio and video player user interfaces. You can preview the entire collection in our media icons catalog.
- First, install the
media-icons
package:
- Import them like so:
- Finally, you can start using them like so:
15. Keep Alive (Optional)
Section titled 15. Keep Alive (Optional)By default, the player and all components will destroy themselves if they’re removed from the
DOM and not reattached after an animation frame tick (i.e., requestAnimationFrame
). If you or
your router are moving player components around the DOM for unknown amounts of time, consider
keeping the player and all children alive, and manually destroying all component instances.
The keep-alive
attribute can be set on any media element, not just the player. Important to note
that it’s forwarded to all children. Any root component with keep-alive
must be destroyed
by calling the destroy()
method on the element instance as shown above.
16. Examples
Section titled 16. ExamplesYou should be all set up by this point. We recommend exploring our 👉 examples to learn how to start building and customizing your player. You can also use the examples to make sure you’ve set everything up correctly.
17. Next Steps
Section titled 17. Next StepsFrom here you’re free to explore the library.
- Scan over the remaining docs pages to get a good overview of how the library works.
- Explore the API and Components references.
- Check out the Default Layout or Plyr Layout pages if you’re using them.
- See the Tailwind Plugin if you’re using Tailwind CSS and building your own layout.
Lastly, remember you’re not alone. You can reach out for help or to talk with other developers using Vidstack: