Get started with text
Learn how to style text, create fonts, and style with rich text tags and style sheets by examples.
읽는 시간 6분최근 업데이트: 7일 전
UI Toolkit uses TextCore to render text, a technology based on TextMesh Pro. TextCore allows advanced styling capabilities and can render text clearly at various point sizes and resolutions. It takes advantage of Signed Distance Field (SDF) font rendering, which can generate font assets that look crisp even when transformed and magnified.
This example demonstrates how to style text in UI Builder, create and apply static and dynamic font assets, use rich text tags and custom style sheets to style text, and create a UITK Text Settings asset to manage the text settings for a panel.
Prerequisites
This guide is for developers familiar with the Unity Editor, UI Toolkit, and C# scripting. Before you start, get familiar with the following:
Create a UITK Text Settings asset
Start with a runtime UI and create a UITK Text Settings asset that manages text settings for the panel. You also create a folder and sub-folders to store font assets and custom style sheets.
Resources- Follow the steps in Get started with Runtime UI to create a simple runtime UI.
- In the folder, create a
Assetsfolder.Resources - Right-click in the folder, and select Create > UI Toolkit > Text Settings to create a
Assets\UI Toolkit. The Inspector window forUITK Text Settings.assetshows the default path names for the font asset, Text Style Sheets asset, Sprite asset, and Color Gradient presets.UITK Text Settings.asset - In the folder, create two folders named
ResourcesandFonts & Materials.Text Style Sheets
Style text with UI Builder
Use UI Builder to style the Toggle text to be bold and italic, and have a font size of . For more information, see Style text with USS.
12px- Double-click to open it in UI Builder.
SimpleRuntimeUi.uxml - In the Inspector window for the Toggle control, select Text.
- In the Font Style field, select B and I.
- In the Size field, enter 12.
Create a static font asset
Create a static font asset and apply it to the Button control. For a static font asset, you don't need to include the source font file in the build. However, you must generate atlas for all the characters in the Button's display text. The display text is and you will add a in the text, so you generate atlas for .
This is a Button*TBhinostua*-
Download the Lato font package from Google Fonts.
-
Unzip the font package file and placein your project's
Lato-Regula.ttffolder.Assets -
In the Inspector window for the font file, confirm the following:
- Include Font Data is enabled.
- Character is set to Dynamic.
-
In the Project window, right-clickand select Create > Text Core > Font Asset > SDF. This creates a dynamic font asset called
Lato-Regula.ttf.Lato-Regula SDF.asset -
In the Inspector window for, set the Atlas Population Mode to Static.
Lato-Regula SDF.asset -
Click Update Atlas Texture.
-
In the Font Asset Creator window, from the Character Set list, choose Custom Characters.
-
In the Custom Characters List box, enter.
TBhinostua* -
Click Generate Font Atlas.
-
Save your changes.
-
Placein the
Lato-Regula SDF.assetfolder.Assets\Resources\Fonts & Materials -
Double-clickto open it in UI Builder.
SimpleRuntimeUi.uxml -
In the Inspector window for the Button control, select Text > Font Asset > Lato-Regula SDF.
Create a dynamic font asset
Create a dynamic font asset and apply it to the TextField control. For a dynamic font asset, you must include the source font file in the build. Import the source font file directly to the path set for the font.
-
Download the Roboto font package from Google Fonts.
-
Unzip the font package file and placein your project's
Roboto-Regular.ttffolder.Assets\Resources\Fonts & Materials -
In the Inspector window for the font file, confirm the following:
- Include Font Data is enabled
- Character is set to Dynamic
-
Right-clickand select Create > Text Core > Font Asset > SDF. This creates a dynamic font asset called
Roboto-Regular.ttf.Roboto-Regular SDF.asset -
Double-clickto open it in UI Builder.
SimpleRuntimeUi.uxml -
In the TextField control's Inspector window, select Text > Font Asset > Roboto-Regular SDF.
Style with rich text tags
Use rich text tags to style text in the Label control.
- Double-click to open it in UI Builder.
SimpleRuntimeUi.uxml - In the panel for the Label control, change Text toInspector
?
. This makes the wordThis is a <font-weight=700><size=2em><color=#FF0000>*Label*</color></size></font-weight>big, red, bold, and with an asterisk on either side of it.Label - Make sure Enable Rich Text is selected.
The label text looks like the following in the Viewport window:

Label text preview shows the word "Label" as big, red, and with an asterisk to either side.
Style with style sheets
To apply the same style for to , create a custom style sheet, and apply the style to both words.
LabelButton-
Right-click in thefolder and select Create > Text Core > Text StyleSheet. This creates a
Assets\Resources\Text Style Sheetsin the path you set in the UITK Text Settings asset.Text StyleSheet.asset -
In the Inspector window for, do the following:
Text StyleSheet.asset- In Name, enter .
ExampleStyle - In Opening Tags, enter .
<font-weight=700><size=2em><color=#FF0000>* - In Closing Tags, enter .
*</color></size></font-weight>
- In Name, enter
-
In the Inspector window for, from the Default Style Sheet list, select Text StyleSheet.
UITK Text Settings.asset -
Double-clickto open it in UI Builder.
SimpleRuntimeUi.uxml -
In the Label control's Inspector window, change Text to.
<s>This is a <style="ExampleStyle">Label</style> -
Make sure Enable Rich Text is selected.
-
In the Button control's Inspector window, change Text to.
<s>This is a <style="ExampleStyle">Button</style> -
Make sure Enable Rich Text is selected.
-
Enter Play mode and check the text in the runtime UI.
-
In the text field, enter some random characters. For a dynamic font asset, the font atlas is dynamically generated as you enter text in the text field.
-
In your project'sfolder, select
Assets\Resources\Fonts & Materials.Roboto-Regular SDF.asset -
In the Inspector window for, select Update Atlas Texture to open the Font Asset Creator window. If the atlas window is hidden, expand it. You should see the characters you entered in the atlas window.
Roboto-Regular SDF.asset

Newly entered characters appear in the font atlas window.