Add styles to UXML
Learn how to reference a USS file in UXML.
읽는 시간 1분최근 업데이트: 한 달 전
In UI Toolkit, you can use USS to customize the appearance of visual elements. 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 attribute of UXML elements:
style<ui:UXML ...> <ui:VisualElement style="width: 200px; height: 200px; background-color: red;" /></ui:UXML>
To reference a stylesheet file, add the element under the root element of a UXML file.
<Style>For example, if you have a USS file named with the following content:
styles.uss#root { width: 200px; height: 200px; background-color: red;}
You can reference it like this:
<ui:UXML ...> <Style src="<path-to-file>/styles.uss" /> <ui:VisualElement name="root" /></ui:UXML>
You can use a relative or an absolute path:
- Absolute paths start from the project's folder and begin with a
Assetsor/. For example,project://database/or/Assets/myFolder/myFile.uss.project://database/Assets/myFolder/myFile.uss - Relative paths start from the current file and exclude the . For example,
/.../myFolder/myFile.uss