files/en-us/web/api/canvasrenderingcontext2d/fontvariantcaps/index.md
{{APIRef("Canvas API")}}
The CanvasRenderingContext2D.fontVariantCaps property of the Canvas API specifies an alternative capitalization of the rendered text.
This corresponds to the CSS {{cssxref("font-variant-caps")}} property.
The font alternative capitalization value, which is one of:
normal (default)
small-caps
smcp).
Small-caps glyphs typically use the form of uppercase letters but are reduced to the size of lowercase letters.all-small-caps
c2sc, smcp).petite-caps
pcap).all-petite-caps
c2pc, pcap).unicase
unic).titling-caps
titl).
Uppercase letter glyphs are often designed for use with lowercase letters.
When used in all uppercase titling sequences they can appear too strong.
Titling capitals are designed specifically for this situation.The property can be used to get or set the font capitalization value.
Note that there are accessibility concerns with some of these, which are outlined in the corresponding font-variant-caps topic.
In this example we display the text "Hello World" using each of the supported values of the fontVariantCaps property.
The value is also displayed for each case by reading the property.
<canvas id="canvas" width="700" height="220"></canvas>
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
ctx.font = "20px serif";
// Default (normal)
ctx.fillText(`Hello world (default: ${ctx.fontVariantCaps})`, 5, 20);
// Capitalization: small-caps
ctx.fontVariantCaps = "small-caps";
ctx.fillText(`Hello world (${ctx.fontVariantCaps})`, 5, 50);
// Capitalization: all-small-caps
ctx.fontVariantCaps = "all-small-caps";
ctx.fillText(`Hello world (${ctx.fontVariantCaps})`, 5, 80);
// Capitalization: petite-caps
ctx.fontVariantCaps = "petite-caps";
ctx.fillText(`Hello world (${ctx.fontVariantCaps})`, 5, 110);
// Capitalization: all-petite-caps
ctx.fontVariantCaps = "all-petite-caps";
ctx.fillText(`Hello world (${ctx.fontVariantCaps})`, 5, 140);
// Capitalization: unicase
ctx.fontVariantCaps = "unicase";
ctx.fillText(`Hello world (${ctx.fontVariantCaps})`, 5, 170);
// Capitalization: titling-caps
ctx.fontVariantCaps = "titling-caps";
ctx.fillText(`Hello world (${ctx.fontVariantCaps})`, 5, 200);
{{ EmbedLiveSample('Examples', 700, 230) }}
{{Specifications}}
{{Compat}}