# Svelte Installation Guide

Install Video.js in Svelte or SvelteKit and build a video player with HTML custom elements

Svelte apps built with Vite, Astro, or SvelteKit use Video.js HTML custom elements directly in their markup. These lightweight, framework-free components build accessible, customizable players with small bundles, advanced features, and consistent behavior across browsers.

> **Tip: Coming from another player?**
>
> Follow the migration guide for [Video.js 8](https://deploy-preview-3023--vjs10-site.netlify.app/docs/framework/html/guides/migrate-from-video-js-8), [Mux Player](https://deploy-preview-3023--vjs10-site.netlify.app/docs/framework/html/guides/migrate-from-mux-player), [Plyr](https://deploy-preview-3023--vjs10-site.netlify.app/docs/framework/html/guides/migrate-from-plyr), [Media Chrome](https://deploy-preview-3023--vjs10-site.netlify.app/docs/framework/html/guides/migrate-from-media-chrome), or [Vidstack](https://deploy-preview-3023--vjs10-site.netlify.app/docs/framework/html/guides/migrate-from-vidstack). Each maps your existing setup onto Video.js v10 instead of starting from scratch.

## AI Quickstart

Copy this prompt into your coding agent. It works as is, or tell it what you're building first.

```
Install the Video.js skill: `npx @videojs/cli agents skills`. Run it and follow the steps for the agent you are running in. If you can't run commands, follow the install instructions at https://github.com/videojs/skills instead. Then use the Video.js skill when you work on video or audio in this project. When installation details are needed, run `npx @videojs/cli agents init --framework svelte` to print the version-matched choices and instructions without changing files.
```

## Installation options for coding agents

The web Markdown page contains the default installation. Add the query parameters below to its `.md` URL for a complete, validated variation. From a project or an offline docs bundle, run the CLI command below instead. Both paths use the same installation renderer and only return instructions; they do not modify a project.

This page fixes the installation method to `packaged` and the framework to `svelte`.

```sh
npx @videojs/cli agents init
```

### Query parameters

- `project`: Whether to adapt the current project or scaffold a new one. New projects need a named app setup. Values: `new`, `existing`. Default: existing.
- `preset`: The player configuration and control set. Values: `video`, `audio`, `live-video`, `live-audio`, `background-video`. Default: video.
- `skin`: The visual skin. Neutral has cleaner surfaces and the same controls as Default. Values: `default`, `neutral`, `compat`, `none`. Default: default. Applies when preset is not background-video.
- `media`: The media source or playback adapter. See the preset compatibility map below. Values: `background-video`, `hls-background-video`, `cloudflare`, `dash`, `hls`, `html5-audio`, `html5-video`, `mux-audio`, `mux-background-video`, `mux-video`, `spotify`, `tiktok`, `twitch`, `vimeo`, `youtube`. Default: the selected preset's first compatible media source.
- `extensions`: A comma-separated list of optional player extensions compatible with the selected player. Pass `none` when no extension is needed. Values: `none`, `google-cast`, `mux-data`. Default: mux-data for Mux media; none otherwise (reported as defaulted).
- `features`: A comma-separated list of player features to add, each with the guide that shows how. Features depend on the preset: audio has no poster or thumbnails, and live streams have no thumbnails. Values: `none`, `captions`, `quality`, `thumbnails`, `poster`, `autoplay`, `keyboard-shortcuts`, `user-preferences`, `internationalization`. Default: none.
- `source-url`: The http:// or https:// media URL placed in the generated player example. Pass `demo` to choose the Video.js demo source for the selected media explicitly. With Mux media, a local file such as `./intro.mp4` adds a step that uploads it with the Mux CLI. Default: the Video.js demo source for the selected media (reported as defaulted).
- `package-manager`: The command runner used for app setup, packages, Shadcn, and the development server. Values: `npm`, `pnpm`, `yarn`, `bun`. Default: pnpm. Applies when method is not cdn with template none.
- `template`: The app setup and file layout. Values: `vite`, `astro`, `sveltekit`. Default: vite.
- `from`: The player an existing project migrates from. The plan adds the migration guide, the checks before changing code, and the cleanup after. Values: `video-js-8`, `mux-player`, `plyr`, `media-chrome`, `vidstack`. Default: none (a new installation). Applies when project=existing.

Run the command above without flags to see the corresponding CLI flags for every framework.

### Decide in this order

1. **Check for a migration.** When the project already plays media with Video.js 8, Mux Player, Plyr, Media Chrome, or Vidstack, pass from with that player, and keep its media URLs as the source.
2. **Inspect the project.** Read package.json, framework config, and lockfiles to infer the framework, app setup, and package manager. React installs @videojs/react; HTML, Vue, and Svelte install @videojs/html.
3. **Choose the starting point.** Use existing when adapting a compatible project. Use new only when the user wants a new app or the intended workspace has no app. Confirm the choice when the workspace and request do not make it clear.
4. **Choose the player.** Use video unless the request signals another experience: audio, music, or podcasts use audio; a live stream uses live-video (hls or mux-video) or live-audio (mux-audio only); a muted, looping decorative video uses background-video. Content hosted on another platform keeps that platform's player even when it is live: youtube, vimeo, twitch, tiktok, and cloudflare use video, and spotify uses audio. Treat comparisons to other products, such as "like Netflix", as describing the experience rather than the media source: build only what Video.js provides, and name anything out of scope, such as chat, playlists, or DRM. Ask only when those signals conflict.
5. **Choose the skin.** Decide whether the project applies its brand to our design or builds its own. When it applies its brand, or asks for a minimal, cleaner, or more subtle look, use neutral: an opinionated design that's easy to brand. When it builds its own design, use none and build the controls from components. When either works or the request doesn't say, use default, the distinctly Video.js design; default and neutral contain the same controls. When the player must work in older browsers, use compat, which keeps fewer features. Ask only when those signals conflict.
6. **Choose the media.** Infer the adapter from the source when possible. Mux wins for Mux playback URLs: stream.mux.com/\<playback-id>.m3u8 or a bare playback ID uses mux-video, mux-audio, or mux-background-video rather than hls. Mux static renditions such as .mp4 or .m4a files use html5-video or html5-audio. Other .m3u8 URLs use hls. Choose a platform adapter only when the content is hosted there, not when the request compares itself to that platform. Without a URL, use hls or dash for a player that should cast, since the default html5-video cannot.
7. **Choose features.** Pass features for what the request asks for, such as captions, a quality menu, or thumbnail previews; the plan points at each feature's guide. Leave it out when the request names none.
8. **Choose extensions.** Mux Data is included by default for Mux video and audio sources. Add Google Cast when a standard or live video player with a ready-made skin plays hls, dash, or mux-video media. Use none when no extension is needed.
9. **Choose how to install.** This guide uses packaged modules, which need a bundler. Match the package manager to the project lockfile. For an existing HTML site without a build step, use CDN scripts instead.
10. **Return one explicit plan.** Confirm the choices once, then pass every applicable query parameter, including `extensions=none` when no extension is needed and `source-url=demo` when there is no media URL yet. Check that Defaulted options says none. Adapt conditional setup steps and existing paths before changing files.

### Compatible media sources by preset

- `video`: `html5-video`, `hls`, `dash`, `mux-video`, `vimeo`, `youtube`, `cloudflare`, `tiktok`, `twitch`
- `audio`: `html5-audio`, `mux-audio`, `spotify`
- `live-video`: `hls`, `mux-video`
- `live-audio`: `mux-audio`
- `background-video`: `background-video`, `hls-background-video`, `mux-background-video`

### App setup by framework

- `svelte`: templates `vite`, `astro`, `sveltekit`

### Installation pages

- [Packaged modules: React](https://deploy-preview-3023--vjs10-site.netlify.app/docs/guides/installation/react.md)
- [Packaged modules: HTML](https://deploy-preview-3023--vjs10-site.netlify.app/docs/guides/installation/html.md)
- [Packaged modules: Vue](https://deploy-preview-3023--vjs10-site.netlify.app/docs/guides/installation/vue.md)
- [Packaged modules: Svelte](https://deploy-preview-3023--vjs10-site.netlify.app/docs/guides/installation/svelte.md)
- [Editable Shadcn source: React source](https://deploy-preview-3023--vjs10-site.netlify.app/docs/guides/installation/shadcn.md?framework=react)
- [Editable Shadcn source: HTML source](https://deploy-preview-3023--vjs10-site.netlify.app/docs/guides/installation/shadcn.md?framework=html)
- [CDN: HTML from jsDelivr](https://deploy-preview-3023--vjs10-site.netlify.app/docs/guides/installation/cdn.md)

## Selected options

- `method`: `packaged`
- `framework`: `svelte`
- `project`: `existing`
- `preset`: `video`
- `skin`: `default`
- `media`: `html5-video`
- `extensions`: `none`
- `source-url`: `https://stream.mux.com/BV3YZtogl89mg9VcNBhhnHm02Y34zI1nlMuMQfAbl3dM/highest.mp4`
- `package-manager`: `pnpm`
- `template`: `vite`

Defaulted options: project, preset, skin, source-url, media, extensions, template, package-manager.

## Reproduce or change these instructions

```sh
npx @videojs/cli agents init --method packaged --framework svelte --project existing --preset video --skin default --media html5-video --extensions none --source-url https://stream.mux.com/BV3YZtogl89mg9VcNBhhnHm02Y34zI1nlMuMQfAbl3dM/highest.mp4 --package-manager pnpm --template vite
```

## Install the packages

```bash
pnpm add @videojs/html@10.0.0
```

## Add your player

Merge the example into the existing Vite route or component that should render the player, and preserve unrelated content.

### `src/lib/VideoPlayer.svelte`

_Merge this into the existing file, or create the file when it is missing._

```svelte
<script lang="ts">
  import '@videojs/html/video/player';
  import '@videojs/html/video/skin';
</script>

<!--
  The player element owns and shares state between the UI
  components and Media. Put layout on the skin or container.
 -->
<video-player>
  <!--
    Skins contain the entire player UI and are easily swappable.
    Add the skin source to your project for full control over its
    UI components.
   -->
  <video-skin>
    <!--
        Media are players without UIs, handling networking
        and display of the media. They are easily swappable
        to handle different sources.
      -->
    <slot />
  </video-skin>
</video-player>

<style>
video-skin {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
}
</style>
```

### `src/App.svelte`

_Merge this into the existing file, or create the file when it is missing._

```svelte
<script lang="ts">
  import VideoPlayer from './lib/VideoPlayer.svelte';
</script>

<VideoPlayer>
  <video src={"https://stream.mux.com/BV3YZtogl89mg9VcNBhhnHm02Y34zI1nlMuMQfAbl3dM/highest.mp4"} playsinline></video>
</VideoPlayer>
```

## Run your app

Start the development server and verify that the selected media plays.

_Long-running: start it in the background, verify the result, then stop it._

```bash
pnpm dev
```

> These are instructions only. Review and run the commands in your project; no files were modified.

That’s it! You now have a working Video.js player.

> **Note: Server rendering with SvelteKit**
>
> Keep the element imports static. SvelteKit renders the custom-element markup on the server, and the browser upgrades it when the page loads. Put code that needs the element or browser APIs in `onMount`. See [Use SvelteKit](https://deploy-preview-3023--vjs10-site.netlify.app/docs/framework/html/guides/svelte#use-sveltekit) for the details.

## Choose what to do next

### Customize

- [Use Video.js with Svelte and SvelteKit](https://deploy-preview-3023--vjs10-site.netlify.app/docs/framework/html/guides/svelte): Read player state in onMount, pass objects as properties, and configure SvelteKit
- [Customize skins](https://deploy-preview-3023--vjs10-site.netlify.app/docs/framework/html/guides/customize-skins#style-a-packaged-skin): Change colors, typography, sizing, and poster presentation
- [Architecture](https://deploy-preview-3023--vjs10-site.netlify.app/docs/framework/html/guides/architecture): Learn how the player, skins, media, and UI components fit together

### Deploy

- [Browser support](https://deploy-preview-3023--vjs10-site.netlify.app/docs/framework/html/guides/browser-support): Check supported browsers and rendering environments
- [TypeScript](https://deploy-preview-3023--vjs10-site.netlify.app/docs/framework/html/guides/typescript): Configure TypeScript for Video.js packages
- [Bundlers](https://deploy-preview-3023--vjs10-site.netlify.app/docs/framework/html/guides/bundlers): Check bundler compatibility
- [Content Security Policy](https://deploy-preview-3023--vjs10-site.netlify.app/docs/framework/html/guides/content-security-policy): Configure Content Security Policy for your player
- [CDN](https://deploy-preview-3023--vjs10-site.netlify.app/docs/framework/html/guides/cdn): See every bundle the CDN serves and the layout rules behind the URLs
- [Self-host the player](https://deploy-preview-3023--vjs10-site.netlify.app/docs/framework/html/guides/self-hosting): Serve the player from your own origin for offline or restricted-network deployments

Something not quite right? You can [submit an issue](https://github.com/videojs/v10/issues) and ask for help, or explore [other support options](https://deploy-preview-3023--vjs10-site.netlify.app/html5-video-support).

---

HTML documentation: https://deploy-preview-3023--vjs10-site.netlify.app/docs/framework/html/llms.txt
All documentation: https://deploy-preview-3023--vjs10-site.netlify.app/llms.txt
