Skip to main content

User Interface

Almost every application needs an interface: a HUD, menus, buttons, dialogs, labels in the scene, or a panel in XR. PlayCanvas lets you build them inside the canvas, from entities, as part of the scene, or outside it with HTML and CSS, and many applications combine the two.

A game interface over a 3D scene: a list in a scrolling panel, a round portrait, health and energy bars, a row of buttons and a toolbar

In-canvas UI is built from components. A screen is the root of an interface, and elements below it are its images, text and groups. Components such as buttons, layout groups and scroll views add behavior on top. They are available whichever way you build: in the Editor, directly against the engine, in PlayCanvas React and in Web Components. Each page in this section explains a concept once and then shows how to apply it on each of those surfaces.

Two Ways to Build UI​

In-canvas UIHTML and CSS
World space and XRScreens can be placed in the scene, and work in XROnly over the canvas
Text inputNone built inText fields, autocomplete, the on-screen keyboard
AccessibilityNot visible to screen readers or keyboard navigationAccessible with the right elements
Styling and layoutAnchors, layout groups, 9-sliced spritesCSS, with the browser's layout and animation
Fonts and emojiMSDF fonts made from your font files, emoji through a canvas fontEvery web font and emoji
EditorBuilt and previewed in the EditorWritten as HTML and CSS assets or files
Canvas capturePart of screenshots and video captures of the canvasNot in captures of the canvas
PerformanceDrawn with the scene, and batchedLaid out and painted by the browser beside the canvas

In-canvas UI suits HUDs, interfaces in the scene or in XR, and anything that must be part of what the canvas shows. HTML suits menus, settings, forms and long text. They mix well: an HTML settings screen can pause an application whose HUD is in the canvas. See HTML and CSS.

Building Blocks​

ComponentRoleEditorReactWeb ComponentsAPI
ScreenThe root of an interface, over the view or in the sceneScreen<Screen><pc-screen>ScreenComponent
ElementAn image, a text or a groupElement<Element><pc-element>ElementComponent
ButtonHover and press states, and click eventsButtonEngine component<pc-button>ButtonComponent
Layout GroupArranges children in rows, columns and gridsLayout GroupEngine component<pc-layout-group>LayoutGroupComponent
Layout ChildOverrides how a layout group sizes a childLayout ChildEngine component<pc-layout-child>LayoutChildComponent
Scroll ViewScrolls content inside a masked viewportScroll ViewEngine component<pc-scroll-view>ScrollViewComponent
ScrollbarA draggable handle on a track, for scroll views and slidersScrollbarEngine component<pc-scrollbar>ScrollbarComponent

PlayCanvas React has components for screens and elements. The others are added as engine components, with a small helper that each page shows.

In This Section​

  • Getting Started - Setting up UI on each surface, and a first interface.
  • Layout
    • Screens - Screen space and world space, scaling to any canvas, pixel ratio and priority.
    • Elements - Anchors, pivots, margins, sizes and group elements.
    • Layout Groups - Rows, columns and grids that arrange their children.
    • Safe Areas - Keeping an interface clear of notches and rounded corners.
  • Images
    • Image Elements - Colors, textures, sprites, 9-slicing, 3D in an image and custom materials.
    • Masks - Clipping children to a rectangle or a shape.
  • Text
    • Text Elements - Size, wrapping, fitting, justification, markup, outlines and shadows.
    • Fonts - Creating and loading font assets, and choosing their characters.
    • Localization - Translations, plurals, locales and fonts for each language.
  • Interaction
    • Input - Mouse, touch and XR events, bubbling, and keeping UI input from the game.
    • Buttons - Hover and press states, tints, sprites and events.
    • Scroll Views - Scrolling content by dragging, the wheel and scrollbars.
  • Common Widgets - Progress bars, sliders, toggles, dialogs, lists, drag and drop and more.
  • World Space and XR
    • World-Space UI - Interfaces in the scene, and labels over characters.
    • UI in XR - Panels, pointing, hands and menus in immersive sessions.
  • HTML and CSS - Interfaces built with the DOM over the canvas.
  • Draw Order and Performance - How UI is drawn, and keeping it fast.
  • Troubleshooting - Common problems and their causes.

See Also​