<mq-piano>
Piano keyboard with realistic key geometry. Configurable range,
accurate or centered black key positioning,
preserve-ratio for real-world proportions. Stylable via
::part() and CSS custom properties. Named slots for per-key annotations.
npm install @hsablonniere/musiq
import '@hsablonniere/musiq/mq-piano';
| Attribute | Property | Type | Default | Description |
|---|---|---|---|---|
start-note |
startNote |
string |
C3 |
First note of the keyboard range. If a black key is specified, the white key before it is included |
end-note |
endNote |
string |
E4 |
Last note of the keyboard range. If a black key is specified, the white key after it is included |
mode |
mode |
'accurate' | 'centered' |
accurate |
Black key positioning: accurate uses real piano geometry, centered centers them between white keys |
preserve-ratio |
preserveRatio |
boolean |
false |
Lock aspect ratio to real piano proportions (the unconstrained dimension is derived from the constrained one) |
| Slot | Description |
|---|---|
note-{name}{octave} |
Per-note content — e.g. note-C3, note-Fs4,
note-Db3. Black keys expose both enharmonic names.
Use s for sharp (♯) since # is not valid in slot names.
|
| Property | Default | Description |
|---|---|---|
--mq-piano-border-color |
#000 |
Base color for all borders (outer + inner) |
--mq-piano-border-width |
1px |
Base width for all borders (outer + inner) |
--mq-piano-border-color-outer |
falls back to border-color |
Color of the outer border around the keyboard |
--mq-piano-border-color-inner |
falls back to border-color |
Color of borders between keys |
--mq-piano-border-width-outer |
falls back to border-width |
Width of the outer border around the keyboard |
--mq-piano-border-width-inner |
falls back to border-width |
Width of borders between keys |
| Part | Description |
|---|---|
key |
All keys (white and black) |
key-white |
White keys only |
key-black |
Black keys only |
Without start-note or end-note, the keyboard covers the default
range C3 → E4.
A standard acoustic piano: 88 keys from A0 to C8.
A0 — C8 · 52 white keys · 36 black keys
2 octaves, C3 → C5
Only one end of the range provided, the other is inferred.
start-note="G2" (end inferred)
end-note="G5" (start inferred)
centered
With mode="centered", every white key has the same width and black keys are
perfectly centered between their neighbors.
mode="accurate" (default)
mode="centered"
Width and color via CSS custom properties.
1px gray
6px red
::part()Harpsichord (inverted colors)
::part()Neon theme
Label each key with note names via named slots.
C major chord highlighted
preserve-ratioLocks the keyboard to realistic piano proportions.
Width constrained: width: 600px — height derived from ratio