For example,
if the site is using a ''--primary-color'' custom property to theme its elements with,
and wanted an SVG background using a ''--color'' custom property to reflect it,
it could write:
.foo {
background-image: url("http://example.com/image.svg" param(--color var(--primary-color)));
}
Using Link Parameters {#using}
=====================
When an external resource link has one or more [=link parameters=] specified,
if the linked resource understands CSS
(such as an SVG or HTML document),
then the initial value of custom properties
with names equal to the keys of the [=link parameters=] map
is set to the corresponding values of the map.
If an ''@property'' rule is specified for one of the custom property names
in the [=link parameters=],
the [=link parameter=] value is used for the initial value,
rather than the ''@property''-specified initial value.
If the linked resource does not understand CSS
(such as PNG images),
then [=link parameters=] have no effect.
Issue: Define a way for the linked resource to specify what link parameters they allow.
For cross-origin iframes/etc,
this will default to
For example, if an SVG image wanted to expose a ''--color'' parameter,
it could use it like:
<svg>
<g style="fill: var(--color);">
<path d="..." />
</g>
</svg>
It's usually a good idea to make your SVG image usable even if no parameters are given,
by providing "default values" for each of the custom properties.
There are several ways to do this.
1. On each ''var()'' function, provide a fallback value, like ''fill: var(--color, blue)''.
2. If the custom property is going to be used a lot,
such that providing a fallback for each individual ''var()'' is troublesome,
store the
custom property in a different name while invoking the default,
like:
:root {
--color2: var(--color, blue);
}
In this example, if ''--color'' is provided via an
SVG parameter,
''--color2'' will receive its value.
If not, it will recieve the default ''blue'' value.
In either case, ''--color2'' can be used in the SVG image's stylesheet unconditionally,
secure in the knowledge that it will always have a value.
3. In a future level of the Custom Properties specification [[CSS-VARIABLES]],
some "parent's value" functionality will be available to make the previous suggestion more usable:
:root {
--color: var(parent --color, blue);
}
(This is an example syntax, and is not yet final.)
By invoking the value of the --color property on the parent
(which, on the root element, refers to the initial value),
an author can avoid self-reference loops while retaining the same
custom property name.