Note that the Rubik's Cube in the previous example is now also in a
defs tag. The Rubik's Cube is reused by the
use tag.
The colors are manipulated using CSS variables. This can't be done with normal CSS traversion because the SVG in the
use tag is in a shadow DOM.
<svg style="display:none;">
<defs>
<g id="single_cube" class="cube-unit">
<rect width="21" height="24" fill="var(--lightColor)" stroke="var(--strokeColor)" transform="skewY(30)" />
<rect width="21" height="24" fill="var(--darkColor)" stroke="var(--strokeColor)" transform="skewY(-30) translate(21 24.3)" />
<rect width="21" height="21" fill="var(--mainColor)" stroke="var(--strokeColor)" transform="scale(1.41,.81) rotate(45) translate(0 -21)" />
</g>
</defs>
<defs>
<g id="big_cube">
<use href="#single_cube" x="121" y="112" />
<use href="#single_cube" x="100" y="124" />
<use href="#single_cube" x="142" y="124" />
<use href="#single_cube" x="121" y="136" />
<use href="#single_cube" x="79" y="136" />
<use href="#single_cube" x="163" y="136" />
<use href="#single_cube" x="142" y="148" />
<use href="#single_cube" x="100" y="148" />
<use href="#single_cube" x="121" y="160" />
<use href="#single_cube" x="121" y="88" />
<use href="#single_cube" x="100" y="100" />
<use href="#single_cube" x="142" y="100" />
<use href="#single_cube" x="121" y="112" />
<use href="#single_cube" x="79" y="112" />
<use href="#single_cube" x="163" y="112" />
<use href="#single_cube" x="142" y="124" />
<use href="#single_cube" x="100" y="124" />
<use href="#single_cube" x="121" y="136" />
<use href="#single_cube" x="121" y="64" />
<use href="#single_cube" x="100" y="76" />
<use href="#single_cube" x="142" y="76" />
<use href="#single_cube" x="121" y="88" />
<use href="#single_cube" x="79" y="88" />
<use href="#single_cube" x="163" y="88" />
<use href="#single_cube" x="142" y="100" />
<use href="#single_cube" x="100" y="100" />
<use href="#single_cube" x="121" y="112" />
</g>
</defs>
</svg>
<svg class="pink-cube" viewBox="0 0 300 230" xmlns="http://www.w3.org/2000/svg">
<use href="#big_cube" />
</svg>
<svg class="blue-cube" viewBox="0 0 300 230" xmlns="http://www.w3.org/2000/svg">
<use href="#big_cube" />
</svg>