Skip to main content

HTML5 Canvas

Draw the score into <canvas> elements instead of SVG. Reach for the Canvas backend when a score is dense enough that the SVG DOM would slow scrolling โ€” think a rehearsal piano-vocal reduction spanning a hundred systems โ€” or when you overlay a matching pixel-perfect canvas on top of the score for animations that need to align with the raster.

When Canvas is the right pickโ€‹

HTML5 Canvas is a Web-only backend โ€” .NET uses Skia, Android uses Skia. On the Web, reach for it when:

  • The score is long or dense. Thousands of SVG nodes slow down scrolling and repaint; a canvas surface stays a single element regardless of note count.
  • You do not need per-element CSS or hit-testing on the DOM. alphaTab's own bounds lookup still works for mouse and touch โ€” see Bounds lookup โ€” but you cannot restyle a single glyph via a CSS selector.
  • You want HighDPI-aware raster output. Canvas honors display.scale and the device pixel ratio, so the render stays sharp on retina and 4K displays.

If you need selectable, styleable, or printable output, stay on SVG. Canvas is the tuning knob for throughput, not the default.

Show it in codeโ€‹

import * as alphaTab from '@coderline/alphatab';

const container = getAlphaTabContainer();
const api = new alphaTab.AlphaTabApi(container, {
core: {
file: '/scores/song.gp',
engine: 'html5',
},
});

getAlphaTabContainer() is the placeholder for the render target โ€” on Web that is the <div> alphaTab attaches to. Canvas is only available on the Web runtime; passing engine: 'html5' from .NET or Android falls back to the platform default.

Where to look nextโ€‹