Title: CSS Linked Parameters Module Level 1 Shortname: css-link-params Level: 1 Status: ED Group: CSSWG Work Status: exploring ED: https://drafts.csswg.org/css-link-params/ Editor: Tab Atkins-Bittner, Google, http://xanthir.com/contact/ Editor: Daniel Holbert, Mozilla Editor: Jonathan Watt, Mozilla Abstract: This spec introduces a way to pass CSS values into linked resources, such as SVG images, so that they can be used as CSS [=custom environment variables=] in the destination resource. This allows easy reuse of "templated" SVG images, which can be adapted to a site's theme color, etc. easily, without having to modify the source SVG. Ignored Terms: css value definition syntax
spec:selectors-4; type:selector; text::hover spec:html; type:element text: iframe text: a spec:fill-stroke-3; type:property; text:fill spec:css-env-1; type:function; text:env()Introduction {#intro} ===================== SVG is stylable with CSS, and when used inline in HTML, this capability can be very useful. For example, an SVG icon can take on a different color based on whether the user is hovering it or not, just by applying a '':hover'' rule to it that changes the 'fill' property. When the SVG is referenced in a way that doesn't allow selectors or CSS inheritance from the outer page to apply to it (such as embedding it via <{img}> or <{iframe}> in HTML), though, this functionality is lost. The only way to change the display of such "external" SVG images is to produce several of them, and change which image you're referencing. This incurs delay on the page as a new resource is downloaded, and disallows dynamic effects like CSS Transitions. CSS link parameters are a way to set CSS custom environment variables on an "external" resource, either by a CSS property or thru a special fragment scheme on the URL. This gives a limited, but powerful, subset of the customizability that "inline" SVG images have to "external" SVG images. A [=link parameter=] is a pair of a <
img {
link-parameters: param(--color, green);
}
.foo {
background-image: url("image.svg", param(--color, green));
}
Name: link-parameters Value: none | <># Initial: none Inherited: no Applies to: all elements and pseudo-elements Computed value: as specified Animation type: discreteThe 'link-parameters' property is one way to set [=link parameters=] on the element itself (if it is an element representing an external resource, such as an HTML <{img}> or <{iframe}>), and on all external CSS resources specified on the element (such as background images, etc). Its values are:
<param()> = param( <In The URL {#url-frag} ---------- A special "fragment identifier" can be used in the fragment of a URL used to reference an external resource. Several examples of existing "fragment identifiers" for SVG documents can be found in the SVG 1.1 specification. The syntax of an SVG parameter fragment identifier is:> , < >? )
param( <(using the CSS value definition syntax; TODO define an actual parser for it).> , < >? )
http://example.com/image.svg#param(--text-color,blue)”.
& character,
as in a URL's query parameters.
http://example.com/image.svg#param(--text-color,blue)¶m(--bg-color,white)”
to set both ''env(--text-color)'' and ''env(--bg-color)''.
.foo {
background-image: url(
"http://example.com/image.svg"
param(--color, var(--primary-color))
);
}
:root {
--color: env(--color, blue);
}
In this example, if ''--color'' is provided via a [=linked parameter=],
''var(--color)'' will contain its value.
If not, it will contain the default ''blue'' value.
In either case, ''var(--color)'' can be used in the stylesheet unconditionally,
secure in the knowledge that it will always have a value.