Buttons and built-in controls
Unity's own controls take the theme in a workspace: Button, Toggle, RadioButtonGroup, Slider, MinMaxSlider, TextField, DropdownField, Foldout, ProgressBar, ToggleButtonGroup and GroupBox. This page lists the classes that you add to a Button or a GroupBox, and the built-in controls that have their own rules. The ButtonsDemo and Styles example scenes show them in a workspace.
The classes are USS classes, so they work in UXML and in code. ButtonStyle has a constant for each class.


Button variants
A Button with no class has the surface color. A variant class changes its meaning:
<ui:Button text="Default" />
<ui:Button text="Save" class="tb-button--primary" />
<ui:Button text="Delete" class="tb-button--danger" />
<ui:Button text="Cancel" class="tb-button--outline" />
<ui:Button text="More" class="tb-button--ghost" />
<ui:Button text="Read the terms" class="tb-button--link" />
save.AddToClassList(ButtonStyle.PRIMARY_CLASS);
| Class | Constant | Look |
|---|---|---|
tb-button--primary |
ButtonStyle.PRIMARY_CLASS |
The main action: --tb-color-accent with --tb-color-accent-text. |
tb-button--danger |
ButtonStyle.DANGER_CLASS |
An action that deletes or loses something: --tb-color-danger with --tb-color-danger-text. |
tb-button--outline |
ButtonStyle.OUTLINE_CLASS |
No fill, a border in --tb-color-border. |
tb-button--ghost |
ButtonStyle.GHOST_CLASS |
No fill and no border. The fill shows under the pointer. |
tb-button--link |
ButtonStyle.LINK_CLASS |
Text in --tb-color-accent, no fill and no border. |
- Under the pointer, a primary or danger button becomes a little transparent. An outline or ghost button gets
--tb-color-surface-hover. A link gets--tb-color-text. - The focused button has a border:
--tb-color-texton a primary or danger button, and--tb-color-accenton the others. - A disabled primary or danger button keeps its color at half opacity. The others have no fill and
--tb-color-text-disabledtext. A hover or a press does not change a disabled button. See Disabled state. - Use one variant class on a button. Use one primary button in a dialog or a form.
Button sizes
<ui:Button text="Small" class="tb-button--sm" />
<ui:Button text="Default" />
<ui:Button text="Large" class="tb-button--lg tb-button--primary" />
<ui:Button text="+" class="tb-button--icon" />
<ui:Button text="+" class="tb-button--icon tb-button--lg" />
| Class | Constant | Look |
|---|---|---|
tb-button--sm |
ButtonStyle.SMALL_CLASS |
At least 18 px high, with --tb-font-size-sm. |
tb-button--lg |
ButtonStyle.LARGE_CLASS |
At least 44 px high, with --tb-font-size-lg. |
tb-button--icon |
ButtonStyle.ICON_CLASS |
A square of 24 px for one icon or one character. With tb-button--sm it is 18 px, and with tb-button--lg it is 32 px. |
A size class works with each variant class, and on a ToggleButton. For a picture, set iconImage of the button and leave the text empty.
Loading state
ButtonStyle.SetLoading shows a button as busy. The button is disabled and shows a spinner in front of its text:
ButtonStyle.SetLoading(save, true);
await SaveAsync();
ButtonStyle.SetLoading(save, false);
| Member | Description |
|---|---|
ButtonStyle.SetLoading(button, loading) |
True disables the button and shows the spinner. False enables it and takes the spinner away. |
ButtonStyle.IsLoading(button) |
True while the button shows the spinner. |
| Class | Element |
|---|---|
tb-button--loading |
On the button while it loads. |
tb-button__spinner |
The spinner, a 12 px ProgressRing with no fixed value. It has the text color of the variant. |
tb-button__text |
The text of the button while it loads. |
- The end of the loading state enables the button. If the button was disabled for another reason, disable it again.
- Do not change
textwhile the button loads. Change it afterSetLoading(button, false).
Button set
A container with the class tb-button-set joins its buttons in one frame. The frame has the border and the round corners, and a line shows between two buttons:
<ui:VisualElement class="tb-button-set">
<ui:Button text="Left" />
<ui:Button text="Center" />
<ui:Button text="Right" />
</ui:VisualElement>
<ui:VisualElement class="tb-button-set tb-button-set--vertical">
<ui:Button text="Top" />
<ui:Button text="Bottom" />
</ui:VisualElement>
| Class | Constant | Element |
|---|---|---|
tb-button-set |
ButtonStyle.SET_CLASS |
The container. Its buttons are in a row. |
tb-button-set--vertical |
ButtonStyle.SET_VERTICAL_CLASS |
Also on the container: the buttons are in a column. |
- The set has the margin and the height of one button, so it lines up with the buttons of its row.
- The set is as wide as its buttons. Put only buttons in it:
Button, ToggleButton or a button with a variant class. - The focused button shows its border in the set.
- A SplitButton is a button set with a main part and an arrow.
- The class
tb-button-groupis not a button set. It is the row of the window buttons in a title bar.
The ToggleButtonDemo scene joins the Bold and Italic buttons of a chat box in a set.
ToggleButtonGroup
Unity's ToggleButtonGroup shows a row of buttons where one or more are on. In a workspace it has the segmented look: one rounded frame holds the buttons, a thin line divides two buttons, and only the two outer ends are round. A button that is on has the accent color. The layout does not move when the pick changes:
<ui:ToggleButtonGroup label="View" name="view">
<ui:Button text="List" />
<ui:Button text="Icons" />
<ui:Button text="Details" />
</ui:ToggleButtonGroup>
var view = root.Q<ToggleButtonGroup>("view");
view.RegisterValueChangedCallback(evt => ShowList(evt.newValue[0]));
Set is-multiple-selection="false" and allow-empty-selection="false" for a segmented control with one pick that is never empty, such as a Mode or Density setting. Outside a workspace, add the class tb-segmented to the group to get the same look.
| Unity class | Look |
|---|---|
unity-button-group |
The frame: the border --tb-segmented-border and the corners --tb-segmented-radius. |
unity-button-group__button |
A segment: --tb-segmented-fill with --tb-segmented-text, and --tb-segmented-fill-hover under the pointer. |
unity-button-group__button:checked |
A segment that is on: --tb-segmented-picked with --tb-segmented-picked-text. |
unity-button-group__button:focus |
The focused segment shows the focus ring in its border. |
unity-toggle-button-group__empty-label |
The text of a group with no buttons: --tb-color-text-muted. |
The --tb-segmented-* variables default to the theme tokens, so the look follows the light, dark, game and high contrast themes. A group sets its own:
.density-group {
--tb-segmented-radius: 4px;
--tb-segmented-picked: rgb(46, 125, 50);
}
Left and Right (the d-pad or the left stick) move the focus between the segments, and Enter or the submit button picks the focused one. The keys never close a window. A disabled group, or a disabled segment, keeps the disabled look.
Icons
A segment with iconImage shows the icon before its text, in the color of the text. Draw the icon in white on a clear background, so the tint can give it any color. Add the class tb-segmented--icons to a group of icons only, to remove the gap after each icon:
<ui:ToggleButtonGroup name="mode"
is-multiple-selection="false"
allow-empty-selection="false">
<ui:Button name="modeSystem" text="System" />
<ui:Button name="modeLight" text="Light" />
<ui:Button name="modeDark" text="Dark" />
</ui:ToggleButtonGroup>
var mode = root.Q<ToggleButtonGroup>("mode");
mode.Q<Button>("modeLight").iconImage =
Background.FromTexture2D(sunIcon);
// One flag for each segment: 0b010 picks Light
mode.value = new ToggleButtonGroupState(0b010, 3);
mode.RegisterValueChangedCallback(evt => ApplyMode(evt.newValue));
In a settings card
A settings row is a Card with the group as its header action. A child with the class tb-card__action goes to the right of the title:
<tb:Card title="Density" description="The space around each line.">
<ui:ToggleButtonGroup name="density"
class="tb-card__action"
is-multiple-selection="false"
allow-empty-selection="false">
<ui:Button text="Comfortable" />
<ui:Button text="Compact" />
</ui:ToggleButtonGroup>
</tb:Card>
From code, add the group with card.Action.Add(density).
For one button that is on or off, use a ToggleButton. The ToggleButtonDemo scene has a Segmented tab with a Mode group of icons and a Density group in a settings card, and it uses a group for the weapon slot of an inventory.
MinMaxSlider
Unity's MinMaxSlider picks a range with two thumbs. In a workspace, the track and the thumbs match the Slider, and the range between the thumbs has the accent color:
<ui:MinMaxSlider
label="Price"
low-limit="0"
high-limit="100"
min-value="20"
max-value="60" />
| Unity class | Look in a workspace |
|---|---|
unity-min-max-slider__tracker |
The track: --tb-color-surface-alt with a border in --tb-color-border. The border is --tb-color-accent while the slider has the focus from a key or a gamepad. |
unity-min-max-slider__dragger |
The range between the thumbs: --tb-color-accent. |
unity-min-max-slider__min-thumb, __max-thumb |
The thumbs: --tb-color-border, and --tb-color-surface-hover under the pointer. |
GroupBox
Add the class tb-group-box to a Unity GroupBox for a border with the title on its top line:
<ui:GroupBox text="Audio" class="tb-group-box">
<ui:Slider label="Music" low-value="0" high-value="100" />
<ui:Slider label="Effects" low-value="0" high-value="100" />
</ui:GroupBox>
| Class | Look |
|---|---|
tb-group-box |
A --tb-color-border border with --tb-radius-md corners, and a margin on top for the title. |
tb-group-box > .unity-group-box__label |
The title, bold, on the top line. Its background is --tb-color-surface, the color of a window, so the line stops under the title. |
On a panel with another background, give the title the same background:
.my-panel .tb-group-box > .unity-group-box__label {
background-color: var(--tb-color-surface-alt);
}
For a group of form fields with the title inside the border, use the class tb-field-set of FormField.
Change the look
Write the rule with .unity-button in front of the class, so it wins over the rule of the control library. Put the sheet after the theme sheet.
/* Round primary buttons */
.unity-button.tb-button--primary { border-radius: 12px; }
/* A wider large button */
.unity-button.tb-button--lg { padding-left: 24px; padding-right: 24px; }
/* The range of a MinMaxSlider in the success color */
.tb-workspace .unity-min-max-slider__dragger {
background-color: var(--tb-color-success);
}
For the rules of the other Unity controls, see Unity controls in the workspace.