Track

Struct Track 

Source
pub struct Track;
Expand description

The <track> element - specifies timed text tracks for media elements.

§Purpose

The <track> element provides text tracks for <audio> and <video> elements. These tracks include subtitles, captions, descriptions, chapters, and metadata. Tracks are in WebVTT format and can be displayed or processed programmatically to enhance media accessibility and user experience.

§Content Categories

  • None (used only within <audio> and <video> elements)

§Permitted Content Model

  • None (void element)

§Common Use Cases

  • Subtitles for foreign language translation
  • Closed captions for deaf and hard-of-hearing users
  • Audio descriptions for blind and low-vision users
  • Chapter markers for video navigation
  • Metadata tracks for programmatic access

§Key Attributes

  • kind: Type of track (“subtitles”, “captions”, “descriptions”, “chapters”, “metadata”)
  • src: URL of the track file (WebVTT format, required)
  • srclang: Language of the track text (required for subtitles)
  • label: User-readable title for the track
  • default: Enable this track by default

§Example

<!-- Video with multiple subtitle tracks -->
<video controls>
  <source src="/videos/movie.mp4" type="video/mp4">
  <track kind="subtitles" src="/subs/en.vtt" srclang="en" label="English" default>
  <track kind="subtitles" src="/subs/es.vtt" srclang="es" label="Español">
  <track kind="subtitles" src="/subs/fr.vtt" srclang="fr" label="Français">
</video>

<!-- Video with captions and descriptions -->
<video controls>
  <source src="/videos/tutorial.mp4" type="video/mp4">
  <track kind="captions" src="/captions/en.vtt" srclang="en" label="English Captions" default>
  <track kind="descriptions" src="/descriptions/en.vtt" srclang="en" label="Audio Descriptions">
  <track kind="chapters" src="/chapters/en.vtt" srclang="en" label="Chapters">
</video>

<!-- Audio with chapter markers -->
<audio controls>
  <source src="/audio/podcast.mp3" type="audio/mpeg">
  <track kind="chapters" src="/chapters/podcast.vtt" srclang="en" label="Episode Chapters">
  <track kind="metadata" src="/metadata/podcast.vtt">
</audio>

§Accessibility

  • Use kind="captions" for accessibility (includes sound effects and speaker identification)
  • Use kind="subtitles" for translation only
  • Provide descriptions for visual content that isn’t conveyed through audio
  • Ensure track files are in proper WebVTT format
  • Set appropriate default tracks based on user preferences

§WHATWG Specification

Trait Implementations§

Source§

impl HtmlElement for Track

Source§

const TAG: &'static str = "track"

The HTML tag name (e.g., “div”, “span”, “img”).
Source§

const VOID: bool = true

Whether this is a void element (self-closing, no children allowed).
Source§

impl CanContain<Track> for Audio

Source§

impl CanContain<Track> for Video

Auto Trait Implementations§

§

impl Freeze for Track

§

impl RefUnwindSafe for Track

§

impl Send for Track

§

impl Sync for Track

§

impl Unpin for Track

§

impl UnwindSafe for Track

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.