<switch>
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The<switch>SVG element evaluates anyrequiredFeatures,requiredExtensions andsystemLanguage attributes on its direct child elements in order, and then renders the first child where these attributes evaluate to true.
Other direct children will be bypassed and therefore not rendered. If a child element is a container element, like<g>, then its subtree is also processed/rendered or bypassed/not rendered.
Note:Thedisplay andvisibility properties have no effect on<switch> element processing. In particular, settingdisplay:none on a child has no effect on the true/false testing for<switch> processing.
In this article
Usage context
| Categories | Container element |
|---|---|
| Permitted content | Any number of the following elements, in any order: Animation elements Descriptive elements Shape elements <a>,<foreignObject>,<g>,<image>,<svg>,<switch>,<text>,<use> |
Attributes
requiredExtensionsA space-separated list of URL values referencing the language extensions the user agent must support for the element to be rendered.
systemLanguageA comma-separated list of supportedlanguage tags.
DOM Interface
This element implements theSVGSwitchElement interface.
Examples
This example demonstrates showing different text content depending on the browser's language settings. The<switch> element will display the first of its child elements whosesystemLanguage attribute matches the user's language, or the fallback element with nosystemLanguage attribute if none of them match.
<svg viewBox="0 -20 100 50"> <switch> <text systemLanguage="ar">مرحبا</text> <text systemLanguage="de,nl">Hallo!</text> <text systemLanguage="en-us">Howdy!</text> <text systemLanguage="en-gb">Wotcha!</text> <text systemLanguage="en-au">G'day!</text> <text systemLanguage="en">Hello!</text> <text systemLanguage="es">Hola!</text> <text systemLanguage="fr">Bonjour!</text> <text systemLanguage="ja">こんにちは</text> <text systemLanguage="ru">Привет!</text> <text requiredExtensions="http://example.org/lang/ext/emoji">☺</text> </switch></svg>Specifications
| Specification |
|---|
| Scalable Vector Graphics (SVG) 2> # SwitchElement> |