Themes in Godot provide a powerful system for styling UI elements. A Theme resource stores colors, fonts, icons, constants, and StyleBoxes that can be applied to Control nodes, allowing consistent visual design across your entire application.
Theme resources can be shared across multiple controls and even exported as separate files for reuse across projects.
Project-wide - Set in ProjectSettings.gui/theme/custom
Branch-level - Assign to a control’s theme property
Local overrides - Use add_theme_*_override() methods
# Apply a theme to a controlvar button = Button.new()var theme = load("res://my_theme.tres")button.theme = themeadd_child(button)
// Apply a theme to a controlvar button = new Button();var theme = ResourceLoader.Load<Theme>("res://my_theme.tres");button.Theme = theme;AddChild(button);
var label = Label.new()label.add_theme_color_override("font_color", Color(1, 0.5, 0))add_child(label)# Reset to theme defaultlabel.remove_theme_color_override("font_color")
var label = new Label();label.AddThemeColorOverride("font_color", new Color(1, 0.5f, 0));AddChild(label);// Reset to theme defaultlabel.RemoveThemeColorOverride("font_color");
var button = Button.new()var custom_font = load("res://fonts/my_font.ttf")button.add_theme_font_override("font", custom_font)button.add_theme_font_size_override("font_size", 24)
var button = new Button();var customFont = ResourceLoader.Load<Font>("res://fonts/my_font.ttf");button.AddThemeFontOverride("font", customFont);button.AddThemeFontSizeOverride("font_size", 24);
var style = new StyleBoxFlat();style.BgColor = new Color(0.2f, 0.3f, 0.4f);style.BorderWidthAll = 3;style.BorderColor = new Color(0, 1, 0.5f);style.CornerRadiusAll = 10;var button = new Button();button.AddThemeStyleboxOverride("normal", style);
Key Properties:
bg_color - Background color
border_width_* - Border width for each side
border_color - Border color
corner_radius_* - Corner radius for rounded corners
var theme = Theme.new()# Set default fontvar font = load("res://fonts/main_font.ttf")theme.default_font = fonttheme.default_font_size = 16# Set colors for all buttonstheme.set_color("font_color", "Button", Color.WHITE)theme.set_color("font_hover_color", "Button", Color(0.95, 0.95, 1.0))# Set StyleBox for buttonsvar button_normal = StyleBoxFlat.new()button_normal.bg_color = Color(0.25, 0.5, 0.75)theme.set_stylebox("normal", "Button", button_normal)# Save theme to fileResourceSaver.save(theme, "res://my_theme.tres")
var theme = new Theme();// Set default fontvar font = ResourceLoader.Load<Font>("res://fonts/main_font.ttf");theme.DefaultFont = font;theme.DefaultFontSize = 16;// Set colors for all buttonstheme.SetColor("font_color", "Button", Colors.White);theme.SetColor("font_hover_color", "Button", new Color(0.95f, 0.95f, 1.0f));// Set StyleBox for buttonsvar buttonNormal = new StyleBoxFlat();buttonNormal.BgColor = new Color(0.25f, 0.5f, 0.75f);theme.SetStylebox("normal", "Button", buttonNormal);// Save theme to fileResourceSaver.Save(theme, "res://my_theme.tres");