Source: Roblox Creator Hub · CC BY 4.0 · View source · Code samples: MIT Imported 2026-10-03. Formatting adapted for this site.
StyleRule
Inherits from: StyleBase → Instance → Object
Defines style properties which override properties on the instances affected by the Selector property.
Inherits from: StyleBase
Memory category: Gui
Properties
| Name | Type / Returns | Description |
|---|---|---|
| StyleRule.Priority | int | A number that determines how properties of the StyleRule apply relative to the same properties in other StyleRules. Higher priority values take precedence over lower. |
| StyleRule.Selector | string | A string specifying which instances the StyleRule should affect. |
| StyleRule.SelectorError | string | A read-only string that displays errors from the Selector property. |
Inherited from Instance
| Name | Type / Returns | Description |
|---|---|---|
| Instance.Archivable | boolean | Determines if an Instance and its descendants can be cloned using Instance:Clone(), and can be saved/published. |
| Instance.archivable | boolean | |
| Instance.Capabilities | SecurityCapabilities | The set of capabilities allowed to be used for scripts inside this container. |
| Instance.IsInSandbox | boolean | Indicates whether the instance is inside a sandboxed container. |
| Instance.Name | string | A non-unique identifier of the Instance. |
| Instance.Parent | Instance | Determines the hierarchical parent of the Instance. |
| Instance.PredictionMode | PredictionMode | Reflects the client-side prediction mode applied to the instance under server-authoritative physics. |
| Instance.RobloxLocked | boolean | A deprecated property that used to protect CoreGui objects. |
| Instance.Sandboxed | boolean | When enabled, the instance can only access abilities in its Capabilities list. |
| Instance.UniqueId | UniqueId | A unique identifier for the instance. |
Inherited from Object
| Name | Type / Returns | Description |
|---|---|---|
| Object.ClassName | string | A read-only string representing the class this Object belongs to. |
| Object.className | string |
StyleRule.Priority
A number that determines how properties of the StyleRule apply relative to the same properties in other StyleRules. Higher priority values take precedence over lower. For example, if a StyleRule with a priority of 10 has an AnchorPoint property of 1, 0 , it will take precedence over lower-priority StyleRules with AnchorPoint properties.
| Field | Value |
|---|---|
| type | int |
| security | {"read":"None","write":"None"} |
| thread safety | ReadSafe |
| category | Data |
| serialization | {"can_load":true,"can_save":true} |
| capabilities | ["UI"] |
StyleRule.Selector
A string specifying which instances the StyleRule should affect. This can be a mix of selectors and combinators to match characteristics such as the class name, instance name, and hierarchy relationships.
For example, ".Container > ImageLabel.BlueOnHover:Hover" effectively means the style rule overrides every ImageLabel that's a child of an instance tagged with Container (.Container > ImageLabel) and is tagged with BlueOnHover (.BlueOnHover) and is in the GuiState.Hover state (:Hover).
Selectors
| Selector | Description | Examples |
|---|---|---|
[class] | Matches instances of a Class.GuiObject or Class.UIComponent class. | "Frame""ImageButton""UICorner" |
.[tag] | Matches instances tagged with a Class.CollectionService tag. | ".Container"".BlueOnHover" |
#[name] | Matches instances of a specific Class.Instance.Name. | "#ModalFrame""#CloseButton" |
:[state] | Matches instances currently in a Enum.GuiState. | ":Hover" |
@[StyleQuery name] | Matches instances with child Class.StyleQuery that has Class.StyleQuery.IsActive|IsActive set to true.There are also built-in selectors for "@ReducedMotionEnabledFalse", "@ReducedMotionEnabledTrue", "@PreferredInputGamepad", "@PreferredInputKeyboardAndMouse", "@PreferredInputTouch", "@PreferredTextSizeMedium", "@PreferredTextSizeLarge", "@PreferredTextSizeLarger", "@PreferredTextSizeLargest", "@ViewportDisplaySizeSmall", "@ViewportDisplaySizeMedium", and "@ViewportDisplaySizeLarge" that can match an instance without a Class.StyleQuery instance. | "@StyleQuerySmall" |
Combinators
| Combinator | Description | Examples |
|---|---|---|
> | Matches instances that are direct children of the previous filter matches. | "Frame > .Inventory" |
>> | Matches instances that are descendants of the previous filter matches. | "ImageButton >> .BlueOnHover" |
, | Specifies a list of multiple independent selectors for the style rule. | "Frame.TagA, TextLabel.TagA" |
:: | Creates a phantom Class.UIComponent instance under the previous filter matches and applies the style rule's properties to it.Multiple instances can be created for Class.StyleQuery and Class.UIStroke by aliasing the instance with a name selector. Some nested instances are supported, including Class.UIGradient under Class.UIStroke or Class.UIConstraint under a Class.UIGridLayout. | "Frame::UICorner" "::UIStroke #Outer" |
| Field | Value |
|---|---|
| type | string |
| security | {"read":"None","write":"None"} |
| thread safety | ReadSafe |
| category | Data |
| serialization | {"can_load":true,"can_save":true} |
| capabilities | ["UI"] |
Code samples: View on Creator Hub (UI-Styling-Class, UI-Styling-Tag, UI-Styling-Modifier, UI-Styling-StyleQuery).
StyleRule.SelectorError
A read-only string that displays errors from the Selector property such as syntax errors, unsupported class types, etc.
| Field | Value |
|---|---|
| type | string |
| tags | ["ReadOnly","NotReplicated"] |
| security | {"read":"None","write":"None"} |
| thread safety | ReadSafe |
| category | Data |
| serialization | {"can_load":false,"can_save":false} |
| capabilities | ["UI"] |
Methods
| Name | Type / Returns | Description |
|---|---|---|
| StyleRule:GetDefaultPropertyTransition | Variant | Returns the default transition applied to all properties of the StyleRule that don't have an explicit transition set. |
| StyleRule:GetProperties | Dictionary | Returns a dictionary of key-value pairs describing the properties of the StyleRule. |
| StyleRule:GetProperty | Variant | Returns the value of a specific property in the StyleRule. |
| StyleRule:GetPropertyTransitions | Dictionary | Returns a dictionary of all property transitions set on the StyleRule. |
| StyleRule:SetDefaultPropertyTransition | () | Sets or clears a default transition that applies to all properties of the StyleRule that don't have an explicit transition set. |
| StyleRule:SetProperties | () | Lets you declare and set multiple properties of the StyleRule at once. |
| StyleRule:SetProperty | () | Sets or updates a single property of the StyleRule. |
| StyleRule:SetPropertyTransition | () | Sets or clears the transition for a single property on the StyleRule. |
| StyleRule:SetPropertyTransitions | () | Lets you declare and set transitions for multiple properties of the StyleRule at once. |
Inherited from StyleBase
| Name | Type / Returns | Description |
|---|---|---|
| StyleBase:GetStyleRules | List | Returns an array of associated StyleRules. |
| StyleBase:InsertStyleRule | () | Inserts a new StyleRule into the array of rules. |
| StyleBase:SetStyleRules | () | Similar to InsertStyleRule() but lets you declare and set multiple StyleRules at once. |
Inherited from Instance
| Name | Type / Returns | Description |
|---|---|---|
| Instance:AddTag | () | Applies a tag to the instance. |
| Instance:children | Instances | Returns an array of the object's children. |
| Instance:ClearAllChildren | () | This method destroys all of an instance's children. |
| Instance:Clone | Instance | Create a copy of an instance and all its descendants, ignoring instances that are not Archivable. |
| Instance:clone | Instance | |
| Instance:Destroy | () | Sets the Instance.Parent property to nil, locks the Instance.Parent property, disconnects all connections, and calls Destroy() on all children. |
| Instance:destroy | () | |
| Instance:FindFirstAncestor | Instance? | Returns the first ancestor of the Instance whose Instance.Name is equal to the given name. |
| Instance:FindFirstAncestorOfClass | Instance? | Returns the first ancestor of the Instance whose Object.ClassName is equal to the given className. |
| Instance:FindFirstAncestorWhichIsA | Instance? | Returns the first ancestor of the Instance for whom Object:IsA() returns true for the given className. |
| Instance:FindFirstChild | Instance? | Returns the first child of the Instance found with the given name. |
| Instance:findFirstChild | Instance | |
| Instance:FindFirstChildOfClass | Instance? | Returns the first child of the Instance whose ClassName is equal to the given class name. |
| Instance:FindFirstChildWhichIsA | Instance? | Returns the first child of the Instance for whom Object:IsA() returns true for the given className. |
| Instance:FindFirstDescendant | Instance? | Returns the first descendant found with the given Instance.Name. |
| Instance:GetActor | Actor? | Returns the Actor associated with the Instance, if any. |
| Instance:GetAttribute | Variant | Returns the value which has been assigned to the given attribute name. |
| Instance:GetAttributeChangedSignal | RBXScriptSignal | Returns an event that fires when the given attribute changes. |
| Instance:GetAttributes | Dictionary | Returns a dictionary of the instance's attributes. |
| Instance:GetChildren | Instances | Returns an array containing all of the instance's children. |
| Instance:getChildren | Instances | |
| Instance:GetDebugId | string | Returns a coded string of the debug ID used internally by Roblox. |
| Instance:GetDescendants | Instances | Returns an array containing all of the descendants of the instance. |
| Instance:GetFullName | string | Returns a string describing the instance's ancestry. |
| Instance:GetStyled | Variant | Returns the styled or explicitly modified value of the specified property, or else the default property value if it hasn't been styled/modified. |
| Instance:GetStyledPropertyChangedSignal | RBXScriptSignal | Returns an event that fires when the given style property changes on the instance. |
| Instance:GetTags | Array | Gets an array of all tags applied to the instance. |
| Instance:HasTag | boolean | Check whether the instance has a given tag. |
| Instance:IsAncestorOf | boolean | Returns true if an Instance is an ancestor of the given descendant. |
| Instance:IsDescendantOf | boolean | Returns true if an Instance is a descendant of the given ancestor. |
| Instance:isDescendantOf | boolean | |
| Instance:IsPropertyModified | boolean | Returns true if the value stored in the specified property is not equal to the code-instantiated default. |
| Instance:QueryDescendants | Instances | Returns an array containing all descendants of the instance that match the selector string. |
| Instance:Remove | () | Sets the object's Parent to nil, and does the same for all its descendants. |
| Instance:remove | () | |
| Instance:RemoveTag | () | Removes a tag from the instance. |
| Instance:ResetPropertyToDefault | () | Resets a property to its default value. |
| Instance:SetAttribute | () | Sets the attribute with the given name to the given value. |
| Instance:WaitForChild | Instance | Returns the child of the Instance with the given name. If the child does not exist, it will yield the current thread until it does. |
Inherited from Object
| Name | Type / Returns | Description |
|---|---|---|
| Object:GetPropertyChangedSignal | RBXScriptSignal | Get an event that fires when a given property of the object changes. |
| Object:IsA | boolean | Returns true if an object's class matches or inherits from a given class. |
| Object:isA | boolean |
StyleRule:GetDefaultPropertyTransition
Returns the default transition applied to all properties of the StyleRule that don't have an explicit transition set. This is equivalent to calling GetPropertyTransitions() and reading the value at key "*".
Returns
| Type | Description |
|---|---|
| Variant | The default transition as a TweenInfo or string token, or nil if no default transition is set. |
| Field | Value |
|---|---|
| security | None |
| thread safety | Unsafe |
| capabilities | ["UI"] |
StyleRule:GetProperties
Returns a dictionary of key-value pairs describing the properties of the StyleRule, for example:
Returns
| Type | Description |
|---|---|
| Dictionary | Dictionary of key-value pairs describing the properties of the StyleRule. |
| Field | Value |
|---|---|
| security | None |
| thread safety | Unsafe |
| capabilities | ["UI"] |
Code samples: View on Creator Hub (StyleRule-GetProperties).
StyleRule:GetProperty
Returns the value of a specific property in the StyleRule.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| name | string | String name of the property, for example "AnchorPoint" or "BackgroundColor3". |
Returns
| Type | Description |
|---|---|
| Variant | Value of the property. |
| Field | Value |
|---|---|
| security | None |
| thread safety | Unsafe |
| capabilities | ["UI"] |
Code samples: View on Creator Hub (StyleRule-GetProperty).
StyleRule:GetPropertyTransitions
Returns a dictionary of all property transitions set on the StyleRule. Each key is a property name (string) and each value is a TweenInfo or a string token that defines the transition's timing for that property.
Returns
| Type | Description |
|---|---|
| Dictionary | Dictionary of key-value pairs mapping property names to their transition parameters. |
| Field | Value |
|---|---|
| security | None |
| thread safety | Unsafe |
| capabilities | ["UI"] |
Code samples: View on Creator Hub (StyleRule-GetPropertyTransitions).
StyleRule:SetDefaultPropertyTransition
Sets or clears a default transition that applies to all properties of the StyleRule that don't have an explicit transition set. This is equivalent to calling SetPropertyTransition() with "*" as the property name.
The transitionParams parameter accepts a TweenInfo that configures the transition's timing. The following TweenInfo properties are used:
Time— Duration of the transition in seconds.EasingStyle— The easing function used for interpolation.EasingDirection— The direction of the easing function.DelayTime— Delay in seconds before the transition starts.
Note that the RepeatCount and Reverses fields of TweenInfo are ignored, as style transitions cannot repeat or reverse automatically.
A per-property transition set via SetPropertyTransition() takes precedence over the default transition for that property.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| transitionParams | Variant | Either a TweenInfo, a token string defining the default transition timing, or nil to remove the default transition. |
Returns
| Type | Description |
|---|---|
| () |
| Field | Value |
|---|---|
| security | None |
| thread safety | Unsafe |
| capabilities | ["UI"] |
StyleRule:SetProperties
Similar to SetProperty() but lets you declare and set multiple properties of the StyleRule at once. Each assignment should be a valid property of the affected GuiObject or UIComponent (UICorner, UIGradient, etc.), and each assigned value should match its property's value type, for example Vector2 for AnchorPoint or Color3 for BackgroundColor3.
Attempts to assign invalid property names such as "AnchorPt" or "BkColor" will silently fail. Type mismatches such as CFrame for AnchorPoint or UDim2 for BackgroundColor3 will also fail and an error will appear in the Output window.
To set/update just one property of a StyleRule, see SetProperty().
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")
-- Get reference to style rule
local frameRule = coreSheet.Frame
-- Set rule properties
frameRule:SetProperties({
["AnchorPoint"] = Vector2.new(0.5, 0),
["BackgroundColor3"] = Color3.new(1, 0, 0.25)
}) Note that you can assign tokens as property values through the $ prefix:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")
local tokensSheet = ReplicatedStorage:FindFirstChild("Tokens")
-- Set tokens (attributes) on tokens sheet
tokensSheet:SetAttribute("TopCenterAnchor", Vector2.new(0.5, 0))
tokensSheet:SetAttribute("MainBackgroundColor", Color3.new(0.2, 0.2, 0.3))
-- Get reference to style rule
local frameRule = coreSheet.Frame
-- Set rule properties
frameRule:SetProperties({
["AnchorPoint"] = "$TopCenterAnchor",
["BackgroundColor3"] = "$MainBackgroundColor"
}) Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| styleProperties | Dictionary | Dictionary of key-value pairs defining the properties to set. |
Returns
| Type | Description |
|---|---|
| () |
| Field | Value |
|---|---|
| security | None |
| thread safety | Unsafe |
| capabilities | ["UI"] |
StyleRule:SetProperty
Sets a new property (or modifies an existing property) for the StyleRule. The name parameter should be a valid property of the affected GuiObject or UIComponent (UICorner, UIGradient, etc.), and the assigned value should match the property's value type, for example Vector2 for AnchorPoint or Color3 for BackgroundColor3.
Attempts to assign invalid property names such as "AnchorPt" or "BkColor" will silently fail. Type mismatches such as CFrame for AnchorPoint or UDim2 for BackgroundColor3 will also fail and an error will appear in the Output window.
To set multiple properties for a StyleRule at once, see SetProperties().
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")
-- Get reference to style rule
local frameRule = coreSheet.Frame
-- Set rule property
frameRule:SetProperty("BackgroundColor3", Color3.new(1, 0, 0.25)) Note that you can assign tokens as property values through the $ prefix:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")
local tokensSheet = ReplicatedStorage:FindFirstChild("Tokens")
-- Set new token (attribute) on tokens sheet
tokensSheet:SetAttribute("MainBackgroundColor", Color3.new(0.2, 0.2, 0.3))
-- Get reference to style rule
local frameRule = coreSheet.Frame
-- Set rule property to use the token as its value
frameRule:SetProperty("BackgroundColor3, "$MainBackgroundColor") Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| name | string | Property name to set, for example "BackgroundColor3". | |
| value | Variant | Property value to set, for example Color3.new(1, 0, 0.25). |
Returns
| Type | Description |
|---|---|
| () |
| Field | Value |
|---|---|
| security | None |
| thread safety | Unsafe |
| capabilities | ["UI"] |
StyleRule:SetPropertyTransition
Sets or clears the transition for a single property on the StyleRule. When a transition is set for a property, any change to that property's styled value will be animated over time instead of applied immediately.
The transitionParams parameter accepts a TweenInfo that configures the transition's timing. The following TweenInfo properties are used:
Time— Duration of the transition in seconds.EasingStyle— The easing function used for interpolation.EasingDirection— The direction of the easing function.DelayTime— Delay in seconds before the transition starts.
Note that the RepeatCount and Reverses fields of TweenInfo are ignored, as style transitions cannot repeat or reverse automatically.
To set transitions for multiple properties at once, see SetPropertyTransitions().
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| property | string | String name of the property to set a transition for, for example "BackgroundColor3" or "Size". | |
| transitionParams | Variant | A TweenInfo or token string defining the transition timing, or nil to remove the transition for this property. |
Returns
| Type | Description |
|---|---|
| () |
| Field | Value |
|---|---|
| security | None |
| thread safety | Unsafe |
| capabilities | ["UI"] |
Code samples: View on Creator Hub (StyleRule-SetPropertyTransition, StyleRule-SetPropertyTransition-Tokens).
StyleRule:SetPropertyTransitions
Similar to SetPropertyTransition() but lets you declare and set transitions for multiple properties of the StyleRule at once.
Calling this method replaces all existing transitions on the StyleRule with the provided set. Each key should be a property name (string) and each value should be a TweenInfo or string token defining the transition timing for that property. Passing nil as a value for a key excludes that property from the resulting transitions.
The following TweenInfo properties are used:
Time— Duration of the transition in seconds.EasingStyle— The easing function used for interpolation.EasingDirection— The direction of the easing function.DelayTime— Delay in seconds before the transition starts.
Note that the RepeatCount and Reverses fields of TweenInfo are ignored, as style transitions cannot repeat or reverse automatically.
To set/update just one property transition on a StyleRule, see SetPropertyTransition().
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| properties | Dictionary | Dictionary of property names to transition parameters. |
Returns
| Type | Description |
|---|---|
| () |
| Field | Value |
|---|---|
| security | None |
| thread safety | Unsafe |
| capabilities | ["UI"] |
Code samples: View on Creator Hub (StyleRule-SetPropertyTransitions, StyleRule-SetPropertyTransitions-Tokens).
Events
Inherited from StyleBase
| Name | Type / Returns | Description |
|---|---|---|
| StyleBase.StyleRulesChanged | Fires when one or more StyleRules is explicitly changed on the connected StyleSheet or StyleRule. |
Inherited from Instance
| Name | Type / Returns | Description |
|---|---|---|
| Instance.AncestryChanged | Fires when the Instance.Parent property of this object or one of its ancestors is changed. | |
| Instance.AttributeChanged | Fires whenever an attribute is changed on the Instance. | |
| Instance.ChildAdded | Fires after an object is parented to this Instance. | |
| Instance.childAdded | ||
| Instance.ChildRemoved | Fires after a child is removed from this Instance. | |
| Instance.DescendantAdded | Fires after a descendant is added to the Instance. | |
| Instance.DescendantRemoving | Fires immediately before a descendant of the Instance is removed. | |
| Instance.Destroying | Fires immediately before (or is deferred until after) the instance is destroyed via Instance:Destroy(). | |
| Instance.StyledPropertiesChanged | Fires whenever any style property is changed on the instance, including when a property is set to nil. |
Inherited from Object
| Name | Type / Returns | Description |
|---|---|---|
| Object.Changed | Fires immediately after a property of the object changes, with some limitations. |