You can enable auto sizing for text with Best Fit. The Best Fit feature allows you to set a minimum and maximum font size for the text element. The text element adjust its font size dynamically based on the content and available space within the range.
Best Fit also supports the following features:
You can enable auto sizing in UI Builder, USS, or C# scripts.
In USS, set the -unity-text-auto-size property to best fit with a minimum and maximum font size. For example:
.labelText {
-unity-text-auto-size: best-fit 5px 100px;
}
To enable auto sizing in C# scripts, use the TextAutoSizeMode property. For example:
textElement.style.unityTextAutoSize = new StyleTextAutoSize(new TextAutoSize(TextAutoSizeMode.BestFit, minSize: 10, maxSize: 100));