Skip to content

SVG2: href must take precedence over xlink:href when both are present #1015

@yisibl

Description

@yisibl

According to the SVG 2 specification, the XLink-based URL reference attributes (such as xlink:href) are deprecated and replaced by the unprefixed href attribute.

The specification explicitly defines the conflict resolution behavior when both attributes are present on the same element:

When the ‘href’ attribute is present in both the XLink namespace and without a namespace, the value of the attribute without a namespace shall be used. The attribute in the XLink namespace shall be ignored.

(Source: SVG 2 – Linking, “Deprecated XLink URL reference attributes”)
https://www.w3.org/TR/SVG2/linking.html

which is not compliant with the SVG 2 specification.

According to the spec, the unnamespaced href attribute must always take precedence when both are present, and xlink:href must be ignored.

This affects elements such as <textPath>, <use>, <image>, <a>, and other elements that accept URL reference attributes.

Demo

<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  <defs>
    <rect id="red" x="0" y="0" width="100" height="100" fill="red"/>
    <rect id="green" x="0" y="0" width="100" height="100" fill="green"/>
  </defs>

  <!-- According to SVG 2, href MUST win, so this should be GREEN -->
  <use
    href="#green" xlink:href="#red"
    x="20" y="20" />
</svg>

resvg 0.46.0

Image

Chrome 143/Firefox 149

Image

WPT

w3c/svgwg#1043

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions