Skip to Content
ReactPiano KeyboardPiano

Piano

The <Piano> React component is a wrapper around the Piano class.

Installation

pnpm add @music-ui/react

Usage

The following code renders an empty keyboard with the default Piano options:

import { Piano } from "@music-ui/react"; // don't forget to import the CSS file too! import "@music-ui/piano/styles.css"; function App() { return ( <main> <h1>My App</h1> {/* rest of your app */} <Piano /> </main> ); }

Output:

Component props

The component accepts the following props:

NameTypeDefault ValueDescription
notesstring | string[]The highlighted notes
noteLabelsstring | string[]The highlighted notes labels
playedNotesstring | string[]The notes being currently played
startOctavenumber3The first rendered octave
octavesnumber2The count of rendered octaves
withFinalCbooleantrueRenders a final C key after the last octave
showOctavesbooleanfalseShows current octave on every C note
idstringThe piano unique identifier
classNamestringThe component class name

Props showcase

A showcase of the component props:

import { Piano } from "@music-ui/react"; import "@music-ui/piano/styles.css"; function App() { return ( <> <Piano octaves={4} showOctaves /> <Piano notes="C4 E4 G4" /> <Piano notes="C4, E4, G4" /> <Piano notes="C4 E4 G4" noteLabels="1 3 5" /> <Piano notes="C4 E4 G4" playedNotes="C4 G4" /> </> ); }

octaves

notes

notes with different voices

notes with noteLabels

notes and playedNotes

Appearance customization

See JavaScript section.

Last updated on