Class Text
A versatile text component that displays text content with customizable size and styling options.
Inheritance
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public sealed class Text : LocalizedTextElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IVisualElementScheduler, IBindable, INotifyValueChanged<string>, ITextEdition, ITextElementExperimentalFeatures, IExperimentalFeatures, ITextSelection, IContextOverrideElement, IAdditionalDataHolder
Remarks
The Text component is a fundamental UI element used to display text content in your application. It provides a range of size options and emphasis variants to help maintain consistency and hierarchy in your text presentation.
Text carries two orthogonal axes, both mirroring the App UI registry: a size drawn from
TextSize (seven steps from XS to XXXL,
defaulting to M) and a variant drawn from
TextVariant (Default, Secondary and
Muted). Sizes resolve to --appui-font-sizes-* tokens and so rescale with
the density; variants resolve to --appui-alias-text-* aliases and so re-resolve
per theme.
For titles and section headers, reach for Heading instead. The component is also localization-ready, inheriting from LocalizedTextElement.
The Text component supports both UXML attributes and runtime property modification, making it flexible for both declarative and programmatic UI development.
Examples
Here's an example of creating a typical text hierarchy using different sizes and variants: Creating a text hierarchy in UXML.
<UXML xmlns="UnityEngine.UIElements">
<Text text="Lead paragraph" size="XXL" />
<Text text="Supporting copy" size="XL" variant="Secondary" />
<Text text="Body text goes here at the default size." />
<Text text="Small caption text" size="XS" variant="Muted" />
</UXML>
For runtime text manipulation: Creating and managing text elements via code.
// Create text elements
var container = new VisualElement();
// Add a title
var title = new Text("Welcome!") ;
container.Add(title);
// Add a subtitle
var subtitle = new Text("Please read the following instructions") ;
container.Add(subtitle);
// Add body text
var body = new Text("Detailed instructions go here...");
container.Add(body);
// Add a quiet caption
var caption = new Text("Last updated 5 minutes ago") ;
container.Add(caption);
Constructors
Text()
Default constructor.
Declaration
public Text()
Text(string)
Construct a Text UI element and use the provided text as display text.
Declaration
public Text(string text)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The text that will be displayed. |
Fields
sizeUssClassName
The Text size styling class.
Declaration
public const string sizeUssClassName = "appui-text--size-"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The Text main styling class.
Declaration
public const string ussClassName = "appui-text"
Field Value
| Type | Description |
|---|---|
| string |
variantUssClassName
The Text variant styling class.
Declaration
public const string variantUssClassName = "appui-text--"
Field Value
| Type | Description |
|---|---|
| string |
Properties
size
The size of the text.
Declaration
[CreateProperty]
[UxmlAttribute]
public TextSize size { get; set; }
Property Value
| Type | Description |
|---|---|
| TextSize |
Remarks
Defaults to M. Each step binds to an --appui-font-sizes-*
token, so the rendered size follows the surrounding density.
variant
The emphasis variant of the text.
Declaration
[CreateProperty]
[UxmlAttribute]
public TextVariant variant { get; set; }
Property Value
| Type | Description |
|---|---|
| TextVariant |
Remarks
Defaults to Default. Each variant binds to a semantic
--appui-alias-text-* token rather than a literal color.
Methods
GetSizeUssClassName(TextSize)
Declaration
public static string GetSizeUssClassName(TextSize enumValue)
Parameters
| Type | Name | Description |
|---|---|---|
| TextSize | enumValue |
Returns
| Type | Description |
|---|---|
| string |
GetVariantUssClassName(TextVariant)
Declaration
public static string GetVariantUssClassName(TextVariant enumValue)
Parameters
| Type | Name | Description |
|---|---|---|
| TextVariant | enumValue |
Returns
| Type | Description |
|---|---|
| string |