Skip to content
Founders offer: 80% off every plan with code FOUNDERS80% off with FOUNDERSGet Magic Glyphs

Fill: icons that show a level

Give an icon a value from 0 to 1 and it fills to that level with its solid look. A half star for a rating, a battery’s charge, an upload’s progress, a cup that fills up. Change the value and the fill eases there. The icon still plays its motion and sound on hover.

starbatteryheartshieldcloudflame
<magic-glyph name="battery" value="0.62" fill-from="left"></magic-glyph>
<magic-glyph name="upload" value="40%"></magic-glyph>
Attribute Values Default
value 0 to 1, or a percentage such as 40%. Leave it off for an icon with no fill. none
fill-from bottom, top, left, right bottom

Change the level from script, and the fill eases there without redrawing the icon:

const icon = document.querySelector('magic-glyph[name="upload"]');
icon.value = 0.8; // same as icon.setAttribute('value', '0.8')

For example, an upload button that fills as the file goes up:

xhr.upload.onprogress = (e) => { icon.value = e.loaded / e.total; };
import { MagicGlyph } from 'magic-glyphs/react';
<MagicGlyph name="star" value={rating / 5} fillFrom="left" label="Rating" />
<MagicGlyph name="battery" :value="charge" fill-from="left" label="Battery" />

A new value eases the fill; the icon is not redrawn. The fill is in the server-rendered HTML too, so the icon shows the right level before the page’s script loads.

The fill takes the icon’s colour. To give it its own colour, set --mg-fill:

magic-glyph.battery-low { --mg-fill: #e5484d; }

The fill uses the icon’s solid style, so set --mg-bg to the colour behind the icon, as for solid icons, when it is not white.

Every icon can take a value. Icons with one large closed shape read best as a level: star, heart, battery, shield, cloud, flame, flask, bucket, piggy bank. Icons drawn only with lines, such as an arrow, change little when filled. Use fill-from="left" for ratings and charge, and the default bottom for things that fill up, like a cup or a jar.

When the icon has a label, the level is added to what screen readers hear: label="Battery" with value="0.62" reads as “Battery, 62%”. When the visitor’s system asks for reduced motion, the fill jumps to the new level instead of easing.

MagicGlyphs.svg(name, { value: 0.5, from: 'left' }) returns the SVG with the fill, and the player from MagicGlyphs.attach() has value(v) to change it. This works on a server too.

The fill is in the web runtime, React and Vue from version 0.10.0. Exports for native apps, Lottie, GIF and video draw icons without a fill for now.