Skip to content

Button ​

A standard button with a text label. Supports hover/active color animations, an optional toggle mode, focus color, rounded corners, optional bevel, and keyboard activation via Enter / Space.

a-sxr-button Component ​

Properties ​

PropertyDescriptionDefault Value
onEvent that triggers onclick actionclick
valueText of button label
font-sizeFont size for button0.2
font-familyFont family for buttonOutfit-Regular.ttf
font-colorText color for button label#F1F5F9
border-colorBorder color of button#1B1B1F
focus-colorFocus color of button#0EA5E9
background-colorBackground color of button#202127
hover-colorBackground color when button is in hover state#0EA5E9
active-colorBackground color when button is pressed down#2563EB
toggleIf true, button acts as toggle button with on/off statefalse
toggle-stateSetting the toggle button on/off statefalse
keyTextual shortcut key that activates the widget (e.g. 'e')
key-codeLegacy numeric shortcut key (e.g. 32 for Space)-1
widthWidth of button1
heightHeight of button1
depthDepth of button0.02
base-depthDepth of the base of the button0.01
gapGap between button and base0.025
marginMargin around button0 0 0 0
radiusCorner radius shared by all four button corners0
bevelIf true, button bevel is enabledfalse
bevel-segmentsSegments of the button bevel5
stepsSteps of the button bevel2
bevel-sizeSize of the button bevel0.1
bevel-offsetOffset of the button bevel0
bevel-thicknessThickness of the button bevel0.1
html
<a-sxr-button
	width="2.5"
	height="0.7"
	base-depth="0.025"
	depth="0.1"
	gap="0.1"

	onclick="buttonActionFunction" key-code="32"
	value="Sample Button"
	font-family="Outfit-Regular.woff2"
	font-size="0.25"
	margin="0 0 0.05 0"

	font-color="black"
	active-color="red"
	hover-color="yellow"
	border-color="white"
	focus-color="black"
	background-color="orange"

	bevel="true"
>
</a-sxr-button>

Rounded corners ​

Set radius to a positive value in scene units to round all four corners of the base and button face. The default, 0, keeps the square appearance. Rounded corners work with or without bevel="true".

html
<a-sxr-button value="Continue" width="2" height="0.6" radius="0.12"></a-sxr-button>

The radius is clamped to half the smaller dimension; a larger value produces a pill-shaped button. The face radius is reduced by gap / 2 to keep the border consistent. Negative or non-finite radii behave as 0.

You can change radius, width, or height after initialization and the geometry updates automatically:

js
button.setAttribute('radius', '0.2')

Interaction ​

  • Click, or focus and press Enter / Space, to activate.
  • The on property names the event that triggers the onclick action and can be rebound after initialization.
  • key / key-code register a global shortcut — see Interaction.
  • Callbacks are global function names; alternatively listen for the widget's own click event.

Toggle mode ​

Set toggle="true" to make the button latch on and off. The current state is held in toggle-state:

html
<a-sxr-button toggle="true" toggle-state="false" value="Sound"></a-sxr-button>
js
button.setAttribute('toggle-state', 'true')