Guide to SVG requiredFeatures and systemLanguage

Scalable Vector Graphics (SVG) includes a conditional processing mechanism that allows elements to be rendered or bypassed based on browser capabilities and user preferences. By utilizing conditional attributes such as requiredFeatures and systemLanguage—often in combination with the SVG <switch> element—developers can create dynamic, localized, and backward-compatible vector graphics. This article explains how these attributes function, how their boolean logic is processed, and their practical implementation within modern web standards.

SVG Conditional Processing Overview

SVG conditional processing evaluates a set of predefined attributes on an element to determine whether that element should be rendered. If any conditional attribute on an element evaluates to false, that element and its children are not rendered.

When elements with conditional attributes are placed inside a <switch> container, the SVG engine evaluates its direct children in order from top to bottom. The engine renders the first child element whose conditions evaluate to true, ignoring all subsequent sibling elements regardless of their evaluation status.

The systemLanguage Attribute

The systemLanguage attribute controls rendering based on the user’s configured language preferences.

<svg viewBox="0 0 300 100" xmlns="http://www.w3.org/2000/svg">
  <switch>
    <!-- Displayed if system language is French -->
    <text x="20" y="50" systemLanguage="fr">Bonjour le monde</text>
    
    <!-- Displayed if system language is Spanish -->
    <text x="20" y="50" systemLanguage="es">Hola Mundo</text>
    
    <!-- Fallback if no matching language is found -->
    <text x="20" y="50">Hello World</text>
  </switch>
</svg>

The requiredFeatures Attribute

The requiredFeatures attribute checks whether the user agent supports specific SVG feature sets or capabilities defined in the SVG specification.

<svg viewBox="0 0 300 100" xmlns="http://www.w3.org/2000/svg">
  <switch>
    <!-- Rendered only if declarative SMIL animation is supported -->
    <circle cx="50" cy="50" r="40" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Animation">
      <animate attributeName="r" values="40;20;40" dur="2s" repeatCount="indefinite"/>
    </circle>
    
    <!-- Static fallback element -->
    <circle cx="50" cy="50" r="40" fill="gray"/>
  </switch>
</svg>

Combined Conditional Evaluation Rules

When multiple conditional attributes—such as systemLanguage, requiredFeatures, and requiredExtensions—are declared on the exact same element, they operate using a logical AND rule:

  1. The element evaluates systemLanguage.
  2. The element evaluates requiredFeatures.
  3. The element only renders if every specified conditional attribute evaluates to true.
  4. If omitted, a conditional attribute defaults to true.