Web - the `<magic-glyph>` element
magic-glyphs.all.jsinside the package contains the 120 free icons. If you have a licence, runnpx magic-glyphs bundle --out magic-glyphs.jsto build the same kind of file with every icon you are licensed for (or name only the icons you need), and load that file instead.
One script defines a custom element that works in any HTML, with or without a framework.
<script src="magic-glyphs.all.js" defer></script><magic-glyph name="heart"></magic-glyph>Attributes
Section titled “Attributes”| Attribute | Values | Default |
|---|---|---|
name |
Any icon name | required |
variant |
outline, solid, duotone, glass |
outline |
size |
Pixels | 24 |
trigger |
hover, click, load, visible, none |
hover |
label |
Text for screen readers. Leave it off for decorative icons. | none |
hover also plays on keyboard focus and on tap. visible plays once when the icon scrolls into view.
Playing from script
Section titled “Playing from script”document.querySelector('magic-glyph').play();A common pattern is to animate the icon when its button is hovered:
<button onmouseenter="this.querySelector('magic-glyph').play()"> <magic-glyph name="trash" trigger="none"></magic-glyph> Delete</button>Colour
Section titled “Colour”Icons take the text colour. See Theming.
Accessibility
Section titled “Accessibility”- Motion is skipped when the visitor’s system asks for reduced motion.
- Without
labelthe icon is hidden from screen readers. Addlabelwhen the icon is the only content of a button or link.
Loading only some icons
Section titled “Loading only some icons”<script src="runtime.js"></script><script> fetch('my-icons.json').then(r => r.json()).then(icons => MagicGlyphs.register(icons));</script>Make my-icons.json with npx magic-glyphs add heart bell --format json and combine the files into one array.
Icons already on the page draw themselves as soon as their data is registered.
Angular
Section titled “Angular”npm install magic-glyphs- In
angular.json, add"node_modules/magic-glyphs/web/magic-glyphs.all.js"to the buildscriptsarray. - Add
schemas: [CUSTOM_ELEMENTS_SCHEMA]to the component (or module) that uses the tag. - Use
<magic-glyph name="heart" [attr.variant]="variant"></magic-glyph>in templates.
WordPress
Section titled “WordPress”- Copy
wordpress/magic-glyphsintowp-content/plugins/and activate Magic Glyphs. - Use the shortcode anywhere shortcodes work:
[magic_glyph name="heart" variant="duotone" size="32" trigger="hover" label="Like"]The script loads only on pages that use the shortcode. The plugin also allows the <magic-glyph> tag in Custom HTML blocks.
Shopify
Section titled “Shopify”- Upload
web/magic-glyphs.all.jsto the theme’s assets. - Save
shopify/magic-glyph.liquidassnippets/magic-glyph.liquid. - Render it in any template or section:
{% render 'magic-glyph', name: 'cart', variant: 'duotone', size: 28, label: 'Cart' %}Every icon has a short synthesized sound that matches its motion. Sound is off unless you ask for it.
<!-- one icon --><magic-glyph name="bell" sound></magic-glyph>
<!-- or every icon on the page --><script>MagicGlyphs.sound.enable(true); MagicGlyphs.sound.volume(0.4);</script>- Position: the sound is placed left or right in stereo according to where the icon sits on screen.
- First interaction: browsers block audio until the visitor clicks or presses a key, so hover sounds start after that.
- React and Vue: pass the
soundprop, or importsoundand callsound.enable(true). - Shape it: change the sound, volume, pitch, speed, tone, stereo and timing per icon. See the Sound page.
- Be considerate: give visitors a mute control if you turn sound on for a whole page.