How Does the SMIL Switch Element Work?
The <switch> element in Synchronized Multimedia
Integration Language (SMIL) provides conditional content selection by
allowing authors to define multiple alternative multimedia elements
inside a single container. A SMIL user agent evaluates the child
elements of a <switch> sequentially from top to
bottom, testing predefined test attributes such as system bitrate,
language, screen size, or caption preferences against the client's
current runtime environment. The player renders the first child element
whose test conditions evaluate entirely to true and ignores
all subsequent siblings, providing a robust mechanism for adaptive
streaming, internationalization, and accessibility.
Sequential Evaluation and First-Match Logic
The core operational model of the <switch> element
relies on ordered evaluation. Unlike general boolean conditionals in
standard programming languages, <switch> operates
strictly on a "first-match-wins" principle.
When a SMIL player encounters a <switch>
block:
- It reads the first child element in document order.
- It evaluates all conditional test attributes defined on that child element.
- If every test attribute on that element evaluates to
true, the player selects and executes that element, immediately terminating the evaluation process for the rest of the<switch>container. - If any test attribute evaluates to
false, the player skips that element entirely and proceeds to the next sibling element. - If none of the conditional children evaluate to
true, the player selects a fallback element—typically a child placed at the very end of the<switch>list that contains no test attributes, guaranteeing that it defaults totrue.
Core System Test Attributes
SMIL defines a standardized set of test attributes that can be
attached to any child element inside a <switch>.
These attributes query the client environment, playback capabilities,
and user preferences.
systemBitrate: Specifies the bandwidth available to the player in bits per second. The player evaluates this totrueif its estimated delivery bandwidth is equal to or greater than the given value. This attribute is foundational for dynamic multi-bitrate streaming.systemLanguage: Specifies a comma-separated list of language tags (e.g.,en,es,fr-CA). It evaluates totrueif the user's configured preferred language matches one of the specified tags.systemCaptions: Tests whether the user has explicitly requested closed captioning. It evaluates totrueif the user enabled captions and the element contains caption data.systemAudioDesc: Evaluates whether the user has enabled audio descriptions for visually impaired audiences.- **
systemScreenSizeandsystemScreenDepth**: Query the physical dimensions and color depth of the target display device, ensuring appropriate video resolution selection for mobile versus desktop displays. systemRequired: Specifies an XML namespace or extension prefix. It evaluates totrueonly if the SMIL player supports that specific module or extension.
Boolean Attribute Combinations
When multiple test attributes are placed on a single child element
inside a <switch>, the engine applies an implicit
logical AND operation across all attributes. For example,
if an element specifies both systemLanguage="es" and
systemBitrate="500000", the player must satisfy both
conditions simultaneously for the element to be chosen. If the user
speaks Spanish but the connection bandwidth is below 500 kbps, the
evaluation fails, and the player advances to the next candidate element
in the sequence.