Version: 2023.1
Language : English
Introduction to UXML
Reuse UXML files

Add styles to UXML

In UI(User Interface) Allows a user to interact with your application. Unity currently supports three UI systems. More info
See in Glossary
Toolkit, you can use USS to customize the appearance of visual elementsA node of a visual tree that instantiates or derives from the C# VisualElement class. You can style the look, define the behaviour, and display it on screen as part of the UI. More info
See in Glossary
. The suggested workflow for USS is that you visually style an element in UI Builder, extract the style to a USS file, and then reference it in UXML.

If you style an element in UI Builder, the style is added as an inline style to the style attribute of UXML elements:

<ui:UXML ...>
    <ui:VisualElement style="width: 200px; height: 200px; background-color: red;" />
</ui:UXML>

To reference a stylesheet file, add the <Style> element under the root element of a UXML file.

For example, if you have a USS file named styles.uss in the same folder of the UXML file with the following content:

#root {
    width: 200px;
    height: 200px;
    background-color: red;
}

You can reference it like this:

<ui:UXML ...>
    <Style src="styles.uss" />
    <ui:VisualElement name="root" />
</ui:UXML>

Additional resources

Introduction to UXML
Reuse UXML files
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961