The complete reference for Spark Player — a dependency-free HTML5 video player with a smart, paginated playlist. Covers every option, method, event and CSS variable, plus integration recipes for vanilla JS, React, Vue and WordPress.
0runtime dependencies
6built-in themes
27typed events
7source families
11locales shipped
Overview
What Spark Player is, and how it is put together.
Spark Player is a single lightweight player that normalises every supported source family behind one consistent interface and one set of controls. You give it a playlist of items; it detects each source kind, mounts the right adapter, renders the controls and playlist, and emits typed events as playback proceeds.
Engine
The SparkPlayer class owns DOM structure, state, i18n and the adapter lifecycle. It implements the controls/playlist host contract.
Adapters
One adapter per source kind — native <video>, HLS via hls.js, and iframe wrappers for YouTube, Vimeo, Dailymotion and Facebook.
Components
Pluggable Controls and Playlist components receive the engine as their host and re-render from a single state store.
Source families detected automatically from the URL:
Six built-in themes, switched with setTheme() or the theme option.
glassDark · cyan
neonDark · magenta
desertWarm · amber
glass-lightLight · sky
neon-lightLight · violet
midnightDeep · indigo
Switching at runtime
player.setTheme('neon');
player.on('themechange', function (e) {
console.log('theme is now', e.theme);
});
Custom themes are just CSS variable sets applied to a .spark--theme-yourname class — see CSS variables.
CSS variables
Every theme is defined by these variables on .spark. Override them globally or per instance.
Variable
Role
--spark-accent
Primary accent (progress fill, active states, focus ring).
--spark-accent-fg
Text / icon colour on top of the accent.
--spark-bg
Player background.
--spark-surface
Raised surfaces (menus, panels).
--spark-fg
Primary foreground text / icons.
--spark-muted
Secondary / muted text.
--spark-radius
Corner radius.
--spark-font
Font stack.
--spark-shadow
Drop shadow.
--spark-control-h
Control-bar height.
--spark-playlist-bg
Playlist panel background.
Custom brand colour
/* globally */
.spark { --spark-accent: #ff5c8a; --spark-radius: 20px; }
/* or per instance via the accent option */
new SparkPlayer('#player', { accent: '#ff5c8a' });
DOM & class names
Stable, BEM-ish class names you can target from your own CSS.
Chapters render as markers on the progress bar; captions appear in a language menu (with an Off entry). Select a track programmatically with player.setTextTrack('en').
Internationalisation
Ship eleven locales, or override any string.
Usage
// built-in locale
new SparkPlayer('#player', { locale: 'zh-CN' });
// override specific strings
new SparkPlayer('#player', {
locale: 'en',
i18n: { play: 'Start', pause: 'Stop' }
});
// standalone translator
import { createI18n } from 'spark-player';
const t = createI18n('en', { playlist: 'Queue' });
t('playlist'); // 'Queue'
Built-in bundles: en (default), en-US, en-GB, zh, zh-CN, es, fr, de, ja, ko, pt-BR. Regional variants fall back to their base language (pt-PT → pt-BR); unknown locales fall back to en. Use availableLocales to list the shipped bundles. Keys include play, pause, mute, unmute, fullscreen, exitFullscreen, pip, settings, captions, captionsOff, quality, speed, theme, next, prev, playlist, nowPlaying, page, prevPage, nextPage, loading, error, retry.
Integration
Copy-paste recipes for the most common stacks.
Vanilla JS
app.js
import { SparkPlayer } from 'spark-player';
import 'spark-player/css';
const player = new SparkPlayer('#player', {
playlist: window.__PLAYLIST__,
theme: 'glass'
});
window.player = player; // handy for debugging
The spark-player/react entry is StrictMode-safe, cleans up on unmount, and exposes a ref with player, transport, setTheme, setPlaylist, toast and getState. Options are read at mount — pass a new key to reconfigure. React is an optional peer.
Vue 3
Video.vue
<template>
<div ref="host"></div>
</template>
<script setup>
import { onMounted, onBeforeUnmount, ref } from 'vue';
import { SparkPlayer } from 'spark-player';
import 'spark-player/css';
const props = defineProps({ playlist: Array });
const host = ref(null);
let player;
onMounted(() => { player = new SparkPlayer(host.value, { playlist: props.playlist }); });
onBeforeUnmount(() => { if (player) player.destroy(); });
</script>
Ships a plugin in wordpress/ with a [spark_player] shortcode and a server-rendered Spark Player block. It enqueues one CSS file plus dist/spark-player.umd.js, needs no jQuery, escapes every attribute and rejects non-HTTP sources. See docs/WORDPRESS.md for the full attribute table and asset resolution.
Built for keyboard-first and assistive technology users.
Key
Action
Space / K
Play / pause
→ / ←
Seek forward / back by seekStep
↑ / ↓
Volume up / down
M
Mute / unmute
F
Toggle fullscreen
N / P
Next / previous item
Tab
Move focus through every control
Enter / Space
Activate the focused control or playlist item
Every interactive control carries an aria-label translated via the active locale, and type="button".
Root state (is-playing, is-fullscreen, is-pip) reflects playback for external styling and testing.
The player honours prefers-reduced-motion and uses semantic landmarks.
Set keyboard: false to opt out of global shortcuts.
Browser support
Modern evergreen browsers, desktop and mobile.
Chrome / Edge
Full support. HLS via hls.js; native PiP.
Firefox
Full support. HLS via hls.js; native PiP.
Safari / iOS
Full support, with native HLS where available.
Mobile
Responsive layout with bottom-sheet playlist.
Third-party embeds (YouTube, Vimeo, Dailymotion, Facebook) require the page to be served over HTTPS to function reliably.
FAQ
Short answers to the usual questions.
Do I need hls.js?
Only for HLS streams in browsers without native HLS support. Install it as an optional peer; the player loads it lazily. Safari plays HLS natively without it.
Does it work without a bundler?
Yes. Load the ESM bundle and stylesheet from a CDN and initialise with a module script — see Installation.
Can I mix source types in one playlist?
Absolutely. Each item's kind is auto-detected from its URL (or forced with kind), so MP4s, HLS streams and embeds can share a single playlist.
How do I theme it?
Pick one of six built-in themes, or override the CSS variables on .spark (or per instance with the accent option). See CSS variables.
Does it support server-side rendering?
The player is browser-only and needs the DOM. In SSR frameworks, create it inside useEffect / onMounted after hydration.