ドキュメント

Unity Engine

Download Unity

Unity Engine

Style UI in-scene

Learn how to style elements with inline styles and USS selectors in the scene.
読み終わるまでの所要時間 2 分最終更新 6日前

Style an element in the Main Stage or in UI Staging mode, using the Style Sheets window (Window > UI Toolkit > Style Sheets) or the
Inspector

?

window.
You can style elements using inline styles or USS selectors. Inline styles are best for single-use or experimental cases, while style sheets are generally easier to manage and more efficient at scale. You can also extract inline styles to a USS class.

Complete class names

When you type in the Style Class List field in the Inspector window, Unity suggests class names used in the style sheets attached to your UXML document, the style sheets they import, and the active theme. Classes already applied to the element aren't suggested.

Generate a selector from an element

To generate a USS selector that matches the selected element:
  1. Right-click an element in the Hierarchy window or in the viewport.
  2. Select Generate Selector From Element.
The Style Sheets window opens with the generated selector pre-filled in the New Selector field. The selector targets the element by its name (
#name
), its last applied class (
.class-name
), or its element type, traversing the parent chain. Confirm the field to add the selector to a style sheet.
Generated selectors match an element precisely, which makes them convenient for one-off styling. However, long, complex selectors can slow down style resolution. For styles you reuse across many elements, write a short class selector instead.

Use the style field context menu

Right-click a style field in the Inspector window to use the following actions:

Action

Description

Go to selectorSelect the USS selector that sets this style.
Open selector in IDEOpen the style sheet in your code editor at that selector.
Set as inline valueSet the computed value as an inline style on the element. When a USS selector is selected, this item is Set as value and writes the value to the selector.
Extract Inlined Style to SelectorMove this inline style to a new class or to an existing USS selector.
Extract All Inlined Styles to SelectorMove all of the element's inline styles to a new class or to an existing USS selector.

Use style category actions

Right-click a style category foldout in the Inspector window to apply actions to every property in that category.

Action

Description

UnsetRemove overrides from all properties in this category. Not available when no properties in the category are overridden.
Unset allRemove all property values in all categories, including non-overridden values.

Additional resources