Skip to main content

Overview

Control nodes are the foundation of Godot’s UI system. All UI elements inherit from the Control base class, which provides positioning, sizing, input handling, and theming capabilities.
Control nodes inherit from CanvasItem, which means they share properties like z_index and visible with other 2D nodes.

The Control Base Class

The Control class provides the fundamental building blocks for UI:
  • Bounding rectangle that defines its extents
  • Anchor position relative to parent control or viewport
  • Offsets relative to the anchor
  • Automatic layout updates when node, parents, or screen size change

Positioning with Anchors and Margins

Anchors allow UI elements to adapt to different screen sizes. Each side of a Control has an anchor value (0.0 to 1.0) that determines its position relative to the parent:
Use set_anchors_preset() to quickly set up common layouts like centering, full rect, or corner anchoring.

Common Layout Presets

Common Control Nodes

Button

A themed button that can contain text and an icon:
Key Properties:
  • text - The button’s display text
  • icon - Optional icon texture
  • flat - Remove button decoration
  • alignment - Text alignment (left, center, right)

Label

Displays plain text with horizontal and vertical alignment:
Key Properties:
  • text - Text to display
  • horizontal_alignment - Left, center, right, or fill
  • vertical_alignment - Top, center, bottom, or fill
  • autowrap_mode - Enable text wrapping
  • clip_text - Clip text outside bounding box

LineEdit

An input field for single-line text editing:
Key Properties:
  • text - Current text value
  • placeholder_text - Hint text when empty
  • secret - Hide characters (for passwords)
  • max_length - Maximum character limit
  • editable - Enable/disable editing
Key Signals:
  • text_changed - Emitted when text changes
  • text_submitted - Emitted on Enter key press
  • editing_toggled - Emitted when entering/exiting edit mode

Minimum Size and Layout

Controls can define a minimum size to ensure proper display:
You can also override _get_minimum_size() to calculate minimum size dynamically.

See Also

Containers

Learn about automatic layout with container nodes

Themes

Customize the appearance of UI elements

Input Handling

Handle mouse, touch, and keyboard input