Skip to content

Label ​

A canvas-rendered text label with wrapping, alignment and optional stroke.

a-sxr-label Component ​

Properties ​

PropertyDescriptionDefault Value
valueText of the label''
aligntext-align: 'left','center','right''center'
anchortext anchor position: 'left','center','right''center'
line-heightline-height of the label0.2
letter-spacingletter spacing of the label0
font-sizeFont size for label0.2
font-familyFont family for labelOutfit-Regular.ttf
font-colorText color of label#F1F5F9
background-colorBackground color of label#202127
opacityOpacity of the label background1.0
text-depthdistance from the text to label background0.01
text-occlusionLet scene geometry occlude the text (opt-in depth test)false
text-stroke-colorColor of the text stroke (canvas stroke style)''
text-stroke-widthWidth of the text stroke (-1 disables)-1
heightHeight of item1
widthWidth of item1
marginMargin around item0 0 0 0
html
<a-sxr-label
	width="2.5" height="0.75"
	value="test label"
	font-family="Outfit-Regular.woff2"
	font-size="0.35"
	line-height="0.8"
	letter-spacing="0"
	margin="0 0 0.05 0"
>
</a-sxr-label>

Multi-line text ​

Text wraps automatically within the label's width. Long text is shrunk with a binary search over font size so it always fits the box rather than overflowing.

Alignment ​

align controls text alignment inside the box (left, center, right) and anchor controls which edge the text block is anchored to.

Text stroke ​

Add an outline for legibility over busy 3D scenes:

html
<a-sxr-label value="Warning"
             text-stroke-color="#000000"
             text-stroke-width="0.02"></a-sxr-label>

A text-stroke-width of -1 (the default) disables the stroke.

Occlusion ​

Labels draw on top of scene geometry by default. Set text-occlusion="true" to let scene geometry occlude the text — see Occlusion.