Skip to content

Link parameters for styling non-inline SVG #996

@o-t-w

Description

@o-t-w

Description

The simplest approach to using SVG is the HTML img element. Unfortunately this approach is the most limited when it comes to styling with CSS, a situation that would be remedied by CSS link parameters. Developers need to be able to change the fill or stroke color for hover/focus/disabled states, for example.

CSS link parameters are a way to set CSS custom environment variables on an "external" resource, either by a CSS property or through a special fragment scheme on the URL.

e.g.

<svg>
  <path fill="env(--color, black)" d="..." />
</svg>
<img src="image.svg#param(--color,green)">
img {
  link-parameters: param(color, green);
}
.foo {
  background-image: url("image.svg", param(--color, green));
}

Specification

https://drafts.csswg.org/css-link-params/

web-feature

No response

Test Links

No response

Additional Signals

In the State of CSS 2025 84 people entered freeform answers about SVG pain points. A large proportion of those comments are complaints such as, to quote:

  • “Cannot use currentColor in svg image, only inline svg”
  • ”Not easily being able to recolor SVG files in CSS.”
  • ”Not being able to (easily) change the stroke-/fill-color of an SVG background-image”
  • “Ability to use currentColor and css variables for SVG set using background-image”

On Stack Overflow variations of the question ”How to change SVG color on hover” are perennial - someone asked for the first time over a decade ago and other people keep asking. Developers clearly need this functionality and have even come up with hacky, inelegant and imprecise solutions such as applying a bunch of CSS filters.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions