When to use the xmlns and version SVG attributes

Published on in SVG

Last updated on

The xmlns attribute is required for SVG files but optional for inlined SVGs. The version attribute is always optional.

Table of contents

  • The xmlns and xmlns:xlink attributes are optional for inlined SVGs in HTML.

  • The xmlns attribute is required for SVG files.

  • The xmlns attribute is required for SVGs in CSS, e.g.:

    background-image: url(
    'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg">...</svg>'
    );
  • The xmlns:xlink attribute is required for SVG files that contain xlink: attributes. Similarly for SVGs in CSS.

The version attribute

The version attribute is ignored and thus always optional. Plus it's deprecated since SVG 2.

Source

Are SVG parameters such as 'xmlns' and 'version' needed? on Stack Overflow