Skip to content
OSMD
Language: English
Sponsor
All guides

Docs · OSMD 3.0

Getting started

OSMD reads a MusicXML file and draws it as sheet music into an element on your page, as SVG. Install it, give it an element, load and render: that’s all a first score takes.

Install

install.sh
npm install opensheetmusicdisplay

Your first score

The page needs an element for OSMD to draw into. With a bundler such as Vite:

index.html
<div id="score"></div>
<script type="module" src="./score.js"></script>

Then load a MusicXML file and render it:

score.js
import { OpenSheetMusicDisplay } from 'opensheetmusicdisplay';

const osmd = new OpenSheetMusicDisplay('score', {
  autoResize: true,
  backend: 'svg',
});
await osmd.load('my-score.musicxml');
osmd.render();

load() takes a URL, a MusicXML string, an XML document or a Blob, from .musicxml, .xml or compressed .mxl files. When the file can’t be read, its promise is rejected with an error that says why. Load the file from a web server: most browsers don’t let a page opened as file:// request other files.

render() lays the score out for the width of its element. With autoResize, which is on by default, OSMD lays it out again when that width changes. In OSMD 3.0 it watches the element itself, so a sidebar that opens or a tab that is shown counts too; up to 2.3.1 it listened to the window.

Without a bundler

The package also contains a browser build, build/opensheetmusicdisplay.min.js, which defines window.opensheetmusicdisplay:

no-bundler.html
<div id="score"></div>
<script src="https://cdn.jsdelivr.net/npm/opensheetmusicdisplay/build/opensheetmusicdisplay.min.js"></script>
<script>
  const osmd = new opensheetmusicdisplay.OpenSheetMusicDisplay('score');
  osmd.load('my-score.musicxml').then(() => osmd.render());
</script>

For a site people rely on, pin the version in the address (opensheetmusicdisplay@3.0.0) or serve the file yourself.

Zoom

zoom.js
osmd.Zoom = 0.8;
osmd.render();

Zoom with a capital Z scales the notes, and render() lays the score out again: at 0.8, each line has room for 1.25 times as much music, so you get more measures per line, not a smaller picture. In 3.0 the zoom stays set when you load another score; up to 2.3.1, load() set it back to 1.

Where to go next

Next: OSMD in React