The AutomaticSize property automatically resizes a parent GuiObject to the size of its descendants. By applying this property, you can dynamically add text and image content to a GuiObject, and its size actively adjusts to fit that content. You can use this property in a variety of use cases, including:
- Scrolling Frames – Automatically resizing the canvas of a ScrollingFrame according to its content.
- Rich Text – Automatically adjusting the size of text objects using rich text markup, including font type and size.
Enabling Automatic Sizing
You can enable the AutomaticSize property for any GuiObject. By default, it is set to None, but you can change its value to have specific control over which direction(s) the GuiObject resizes to fit its content.
To enable the AutomaticSize property:
In the Properties window, navigate to the AutomaticSize property and set it to one of the following options:
X - Resizes content horizontally.
Y - Resizes content vertically.
XY - Resizes content both horizontally and vertically.
Customizing Automatic Sizing
Similar to the typical process of sizing a GuiObject, automatic sizing takes the AnchorPoint property into consideration when it's resizing content. For example, the following video displays three TextLabels that are automatically sizing their text content:
For example, the following white Frame has an X-axis size of 0, so it doesn't have a minimum width and can resize to the width of its child object.
In comparison, the following white Frame has an X size of 100, so it cannot resize smaller than 100 pixels.
When you enable the TextWrapped property for a TextLabel, TextButton, or TextBox and set the AutomaticSize property to either Y or XY, the label resizes to accommodate any text that wraps across multiple lines. For example, the following TextLabel has TextWrapped enabled and a set AutomaticSize property of Y, so when a user types in more content, the TextLabel expands vertically.
Instead of enabling the TextScaled property for any TextLabels, TextButtons, and TextBoxes, use the AutomaticSize property for a GuiObject instead. This ensures that the text within your text objects maintains a consistent text size and never scales to a font size that is illegible. For more information, see the API Reference for TextLabel.TextScaled, TextButton.TextScaled, and TextBox.TextScaled.