Sheet music of Twinkle Twinkle Little Star

The final project in my 1st year web development class is to design and develop a site to teach a skill. This semester, several students are creating sites with musical themes: how to play guitar, read sheet music, etc. That got me thinking: what’s the best way to create musical notation on a modern website?

Most digital sheet music is delivered in a format that’s indistinguishable from the bound papers we remember from childhood lessons, only locked into PDFs. To present musical notation in an accessible, usable way on the web, we need to take a different approach.

Musical Characters

Most developers don’t realise that there are dozens of musical symbols buried in most typefaces, easily accessible through codes or a glyph. While not enough to reproduce a complex score, these symbols are enough to render basic musical phrases on web pages.

So long as you’re encoding your page in UTF-8, you should be able to simply copy and paste the glyphs directly into your markup:

<li>♪</li>

You can take the same approach with CSS generated content:

li:before { content: "♯"; }

For the sake of convenience, I’ve also included the decimal and hexadecimal entities for each glyph; these should be used if with JavaScript or in MySQL, as using Unicode characters can cause errors if they are inserted directly into MySQL feilds.

Notes, Flats, Sharps & Clefs

HTML EntityHex EntityProducesDescription
&#9833;\2669quarter note
&#9834;\266aeighth note
&#9835;\266bbeamed eighth note
&#9836;\266cbeamed sixteenth note
&#9837;\266fflat
&#9838;\2670natural
&#9839;\2671sharp
&#119082;\x1d12a𝄪double sharp
&#119083;\x1d12b;𝄫double flat
&#119070;\x1d11e;𝄞G clef
&#119073\x1d121𝄡C clef
&#119074;\x1d122𝄢F clef

Pauses, Bar Lines, Sound Levels & Repeats

HTML EntityHex EntityProducesDescription
&#119058;\2669𝄒breath mark
&#119056;\x1d110𝄐fermata
&#119057;\x1d111𝄑fermata below
&#119186;\x1d192𝆒crescendo
&#119187;\x1d193𝆓decrescendo
&#119040;\x1d100𝄀single bar line
&#119041;\x1d101𝄁double bar line
&#119042;\x1d102𝄂final bar line
&#119043;\x1d103𝄃reverse final bar line
&#119044;\x1d104𝄄dashed bar line
&#119045;\x1d105𝄅short bar line
&#119046;\x1d106𝄆left repeat
&#119047;\x1d107𝄇right repeat

You will tend to find better support for musical notation symbols on OS X than Windows, particularly in the six-digit decimal entity range. The basic symbols - quarter notes through to the sharp symbol - have good support across all platforms and browsers.

One significant advantage of using these entities is their built-in support for accessibility: many text-to-speech converters will read the quarter-note symbol as exactly that. However, their severe limitations across platforms mean that they can't be used for crafting realistic sheet music: you should probably consider these entities for decoration, rather than information.

There are a few more music symbols that are common in typefaces (at least on the Mac side), but I’m going to assume that most readers aren’t interested in using mensural notation to represent medieval choral music.

Enjoy this piece? I invite you to follow me at twitter.com/dudleystorey to learn more.
Check out the CodePen demo for this article at https://codepen.io/dudleystorey/pen/PwXqYO