この記事はまだボランティアによって 日本語 に翻訳されていません。ぜひ MDN に参加して翻訳を手伝ってください!
この記事を English (US) で読むこともできます。

The <switch> SVG element evaluates the requiredFeatures, requiredExtensions and systemLanguage attributes on its direct child elements in order, and then processes and renders the first child for which these attributes evaluate to true. All others will be bypassed and therefore not rendered. If the child element is a container element such as a <g>, then the entire subtree is either processed/rendered or bypassed/not rendered.

Note that the values of properties display and visibility have no effect on switch element processing. In particular, setting display to none on a child of a switch element has no effect on true/false testing associated with switch element processing.

Usage context

CategoriesContainer element
Permitted contentAny number of the following elements, in any order:
Animation elements
Descriptive elements
Shape elements
<a>, <foreignObject>, <g>, <image>, <svg>, <switch>, <text>, <use>

Attributes

Global attributes

DOM Interface

This element implements the SVGSwitchElement interface.

SVG <switch> example

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 whose systemLanguage attribute matches the user's language, or the element with no systemLanguage attribute if none of them matches.

HTML Content

<svg width="100%" viewBox="0 -20 100 50">
   <switch>
      <text systemLanguage="ar">مرحبا</text>
      <text systemLanguage="de,nl">Hallo!</text>
      <text systemLanguage="en">Hello!</text>
      <text systemLanguage="en-us">Howdy!</text>
      <text systemLanguage="en-gb">Wotcha!</text>
      <text systemLanguage="en-au">G'day!</text>
      <text systemLanguage="es">Hola!</text>
      <text systemLanguage="fr">Bonjour!</text>
      <text systemLanguage="ja">こんにちは</text>
      <text>☺</text>
   </switch>
</svg>

Result

Specifications

Specification Status Comment
Scalable Vector Graphics (SVG) 2
The definition of '<switch>' in that specification.
Candidate Recommendation Clarified the evaluation of the systemLanguage attribute
Scalable Vector Graphics (SVG) 1.1 (Second Edition)
The definition of '<switch>' in that specification.
Recommendation Initial definition

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support1 Yes4983.1
allowReorder ? ? Yes — 50 ? ? ?
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support31 Yes4 ?3.1 ?
allowReorder ? ? ? Yes — 50 ? ? ?

ドキュメントのタグと貢献者

 このページの貢献者: fscholz, mattwojo, y6nH, Sebastianz, kscarfone, Jeremie, trevorh, Manuel_Strehl, Longsonr
 最終更新者: fscholz,