# AR Button An A-Frame component and primitive for creating buttons. Buttons respond to clicks and are used to perform some action. They're customizable and built on top of the [ar-clickable](./ar-clickable.md) component. !!! tip "Important" AR Buttons **require** an [ar-pointer-tracker](../api/plugin-aframe.md#ar-pointer-tracker) in your scene! ![AR Buttons](../img/addon-buttons.gif){ .responsive } ## Properties | Property | Description | Default | | -------- | ----------- | ------- | | `enabled` | Whether or not the button is enabled. | `true` | | `src` | The graphic of the button. If none is provided, a default graphic is used. | `""` | | `width` | The width of the button. | `0.5` | | `height` | The height of the button. | `0.5` | | `color` | The color tint of the button. | `"white"` | | `pressed-color` | The color tint of the button when pressed. | `"#ffd855"` | | `disabled-color` | The color tint of the button when disabled. | `"gray"` | ## Look and feel ### Setting the text You can set a text by attaching the `text` component to your ``: ```html ``` Refer to the [documentation of the text component](https://aframe.io/docs/1.7.0/components/text.html){ ._blank } for more details. ### Changing the colors Changing the colors is simple to do: ```html ``` ### Customizing the graphic You can also customize the graphic of your `` by changing its `src` property. You'll typically set it to a query selector that refers to an image: ```html ``` !!! tip "Tip: changing the graphic when pressed" If you also want to change the graphic of the button when it's being pressed, set its `pressed-color` to white and employ `ar-onmousedown` and `ar-onmouseup` as follows: ```html ``` ## Detecting clicks ### Using ar-onclick AR Buttons are built on top of [AR Clickables](./ar-clickable.md) and respond to the [same events](./ar-clickable.md#events). In particular, the `"click"` event should be listened to in order to initiate an action. The `ar-onclick` component makes that really easy: ```html ``` Button clicks can also affect other entities: ```html ``` Refer to the documentation of [ar-clickable](./ar-clickable.md#declarative-handlers) for details on `ar-onclick`. ### Using JavaScript While `ar-onclick` is easy-to-use, it's limited to setting properties. For advanced usage, you need JavaScript. Write a component and listen to the `"click"` event as in the template below: ```js /* Usage: */ AFRAME.registerComponent('do-something-on-click', { dependencies: [ 'ar-button' ], init() { this._onclick = this._onclick.bind(this); }, play() { this.el.addEventListener('click', this._onclick); }, pause() { this.el.removeEventListener('click', this._onclick); }, _onclick() { console.log('Do something! ;)'); }, }); ```