Skip to Content
API ReferenceTextStyle

TextStyle

live Describes the visual style of a text label, including font size, color, weight, decoration, alignment, and font asset.

Constructor

TextStyle

live Describes the visual style of a text label, including font size, color, weight, decoration, alignment, and font asset.

ParameterDescription
FontSizeThe font size in logical pixels. Null inherits from the parent.
ColorThe text color. Null inherits from the parent.
BoldWhether the text is bold.
ItalicWhether the text is italic.
UnderlineWhether the text is underlined.
LetterSpacingAdditional spacing between characters in logical pixels.
LineHeightLine height as a multiplier of the font size. Null uses the default.
TextAlignHorizontal and vertical text alignment within the label bounds. Null inherits from the parent. Maps to style.unityTextAlign.
FontAssetSDF font asset for rendering. Null falls back to FontFamily, then Unity’s default. Maps to style.unityFontDefinition via FontDefinition.FromSDFFont.
ResetPaddingWhen true, zeroes out the UIToolkit Label’s built-in padding and margin. Use when the label is inside a flex container that handles its own centering, to prevent intrinsic Label padding from offsetting the visual result.

Properties

Bold

Whether the text is bold.

Color

The text color. Null inherits from the parent.

FontAsset

SDF font asset for rendering. Null falls back to FontFamily, then Unity’s default. Maps to style.unityFontDefinition via FontDefinition.FromSDFFont.

FontSize

The font size in logical pixels. Null inherits from the parent.

Inherit

A text style with no overrides, inheriting all values from the parent.

Italic

Whether the text is italic.

LetterSpacing

Additional spacing between characters in logical pixels.

LineHeight

Line height as a multiplier of the font size. Null uses the default.

ResetPadding

When true, zeroes out the UIToolkit Label’s built-in padding and margin. Use when the label is inside a flex container that handles its own centering, to prevent intrinsic Label padding from offsetting the visual result.

TextAlign

Horizontal and vertical text alignment within the label bounds. Null inherits from the parent. Maps to style.unityTextAlign.

Underline

Whether the text is underlined.

Methods

AsBold

Returns a copy of this style with Bold set to true.

AsItalic

Returns a copy of this style with Italic set to true.

AsUnderlined

Returns a copy of this style with Underline set to true.

WithColor

Returns a copy of this style with the given Color.

ParameterDescription
colorThe text color.

WithLetterSpacing

Returns a copy of this style with the given LetterSpacing.

ParameterDescription
spacingAdditional spacing between characters in logical pixels.

WithLineHeight

Returns a copy of this style with the given LineHeight.

ParameterDescription
lineHeightLine height as a multiplier of the font size.

WithSize

Returns a copy of this style with the given FontSize.

ParameterDescription
sizeThe font size in logical pixels.
Last updated on