Skip to main content

Overview

Containers are specialized Control nodes that automatically arrange their children. They handle positioning, sizing, and spacing without manual intervention, making it easier to create responsive, adaptive UIs.
All containers inherit from the Container base class and only work with children that inherit from Control.

Container Base Class

The Container class provides the foundation for all container types:
  • Automatically arranges child controls
  • Emits signals when children need to be sorted
  • Provides accessibility region support
  • Mouse filter set to MOUSE_FILTER_PASS by default

Important Signals

  • pre_sort_children - Emitted before sorting children
  • sort_children - Emitted when children need to be sorted

Box Containers

VBoxContainer

Arranges children vertically from top to bottom:

HBoxContainer

Arranges children horizontally from left to right:
Use size_flags_horizontal and size_flags_vertical to control how children expand within containers.

Grid Container

Arranges children in a grid layout with a specified number of columns:
Key Properties:
  • columns - Number of columns in the grid
Theme Properties:
  • h_separation - Horizontal spacing between children (default: 4)
  • v_separation - Vertical spacing between children (default: 4)

Size Flags

Control how children behave within containers using size flags:

Other Container Types

MarginContainer

Adds margins around its single child:

CenterContainer

Centers its single child:

PanelContainer

Provides a themed panel background for its children:

ScrollContainer

Provides scrolling for content larger than its visible area:

Best Practices

Combine different container types to achieve complex layouts. For example, use VBoxContainer for vertical sections and HBoxContainer within each section for horizontal arrangements.
Define custom_minimum_size on controls to ensure proper layout, especially in containers that expand children.
Master the size flags system to control how elements behave in different screen sizes and orientations.
Always test your UI at different resolutions to ensure containers adapt properly.

See Also

Control Nodes

Learn about the Control base class and common UI elements

Themes

Customize container appearance and spacing