Pixel UI/Games & sound/Chiptune

Chiptune

8-bit sounds for your whole page, from one tag. No audio files.

<piix-chiptune>DOM + canvas

Click to hear. Browsers wait for your first click before any sound.

Coin Jump Power up Error
Speaker

Drop it anywhere and the page gets sound: links and buttons blip when you hover and click them, and every Piixpal game and dialogue box starts making noise. Each sound is made on the spot with WebAudio, so there's nothing to download. It shows as a pixel speaker; clicking it mutes the whole page, and the choice is remembered. Put data-sfx="coin" on anything to give it a sound of its own.

Installation

<!-- once, anywhere on the page: every component -->
<script src="https://cdn.jsdelivr.net/npm/piixpal@0.6/piixpal.min.js"></script>

Usage

<piix-chiptune></piix-chiptune>

<piix-button data-sfx="coin">Coin</piix-button>
<piix-button tone="sky" data-sfx="jump">Jump</piix-button>
<piix-button tone="violet" data-sfx="powerup">Power up</piix-button>
<piix-button tone="coral" data-sfx="error">Error</piix-button>

Examples

Every sound

All of them are generated, so they cost no bytes to load.

hover click blip select type coin jump bounce launch hit break powerup success error open close lose win boot

From your own code

Piixpal.sfx(name, { pitch }) plays a sound when something happens.

Save Higher coin

Pinned to a corner

Look at the bottom-right corner of this page.

API reference

AttributeWhat it doesDefault
wirewhat gets sound by itself: hover, click, both or nonehover click
scopea CSS selector: only wire things inside itthe whole page
volume0 to 1.25
floatbottom-right bottom-left top-right top-left–
tonethe speaker's colourlime
data-sfxon any element: the sound it makes when clicked–
data-sfx-hoveron any element: the sound when the pointer arrives–

Events

EventWhen
mutethe speaker was clicked: detail.muted

Methods

MethodWhat it does
Piixpal.sfx(name, { pitch })play any sound from code
.mutedread or set the mute switch

Accessibility