Collapse Sidebar




TextXAlignment determines the horizontal alignment (X-axis) of text rendered within a UI element’s space. It functions similarly to the CSS text-align property, with left, right and center values (there is no justify option). For Left and Right, text is rendered such that the left/right text bounds just touch the edge of the UI element rectangle. For Center, each line of text is centered on the very center of the UI element rectangle.

This property is used in conjunction with TextBox/TextYAlignment to fully determine text alignment on both axes. This property won’t affect the read-only properties TextBox/TextBounds and TextBox/TextFits.

Code Samples

Text Alignment

This code sample shows all the different text alignment combinations by iterating over each enum item. It is meant to be placed within a TextLabel, TextButton or TextBox.

-- Paste this in a LocalScript within a TextLabel/TextButton/TextBox
local textLabel = script.Parent

local function setAlignment(xAlign, yAlign)
	textLabel.TextXAlignment = xAlign
	textLabel.TextYAlignment = yAlign
	textLabel.Text = xAlign.Name .. " + " .. yAlign.Name

while true do
	-- Iterate over both TextXAlignment and TextYAlignment enum items
	for j, yAlign in pairs(Enum.TextYAlignment:GetEnumItems()) do
		for i, xAlign in pairs(Enum.TextXAlignment:GetEnumItems()) do
			setAlignment(xAlign, yAlign)