Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

RichTextLabel

Inherits: Control < CanvasItem < Node < Object

A control for displaying text that can contain different font styles, images, and basic formatting.

Description

A control for displaying text that can contain custom fonts, images, and basic formatting. RichTextLabel manages these as an internal tag stack. It also adapts itself to given width/heights.

Note: Assignments to text clear the tag stack and reconstruct it from the property's contents. Any edits made to text will erase previous edits made from other manual sources such as append_text and the push_* / pop methods.

Note: RichTextLabel doesn't support entangled BBCode tags. For example, instead of using [b]bold[i]bold italic[/b]italic[/i], use [b]bold[i]bold italic[/i][/b][i]italic[/i].

Note: push_*/pop_* functions won't affect BBCode.

Note: Unlike Label, RichTextLabel doesn't have a property to horizontally align text to the center. Instead, enable bbcode_enabled and surround the text in a [center] tag as follows: [center]Example[/center]. There is currently no built-in way to vertically align text either, but this can be emulated by relying on anchors/containers and the fit_content property.

Tutorials

Properties

AutowrapMode

autowrap_mode

3

bool

bbcode_enabled

false

bool

clip_contents

true (overrides Control)

bool

context_menu_enabled

false

Array

custom_effects

[]

bool

deselect_on_focus_loss_enabled

true

bool

drag_and_drop_selection_enabled

true

bool

fit_content

false

bool

hint_underlined

true

String

language

""

bool

meta_underlined

true

int

progress_bar_delay

1000

bool

scroll_active

true

bool

scroll_following

false

bool

selection_enabled

false

bool

shortcut_keys_enabled

true

StructuredTextParser

structured_text_bidi_override

0

Array

structured_text_bidi_override_options

[]

int

tab_size

4

String

text

""

TextDirection

text_direction

0

bool

threaded

false

int

visible_characters

-1

VisibleCharactersBehavior

visible_characters_behavior

0

float

visible_ratio

1.0

Methods

void

add_image ( Texture2D image, int width=0, int height=0, Color color=Color(1, 1, 1, 1), InlineAlignment inline_align=5, Rect2 region=Rect2(0, 0, 0, 0), Variant key=null, bool pad=false, String tooltip="", bool size_in_percent=false )

void

add_text ( String text )

void

append_text ( String bbcode )

void

clear ( )

void

deselect ( )

int

get_character_line ( int character )

int

get_character_paragraph ( int character )

int

get_content_height ( ) const

int

get_content_width ( ) const

int

get_line_count ( ) const

float

get_line_offset ( int line )

PopupMenu

get_menu ( ) const

int

get_paragraph_count ( ) const

float

get_paragraph_offset ( int paragraph )

String

get_parsed_text ( ) const

String

get_selected_text ( ) const

int

get_selection_from ( ) const

int

get_selection_to ( ) const

int

get_total_character_count ( ) const

VScrollBar

get_v_scroll_bar ( )

int

get_visible_line_count ( ) const

int

get_visible_paragraph_count ( ) const

void

install_effect ( Variant effect )

bool

is_menu_visible ( ) const

bool

is_ready ( ) const

void

menu_option ( int option )

void

newline ( )

void

parse_bbcode ( String bbcode )

Dictionary

parse_expressions_for_values ( PackedStringArray expressions )

void

pop ( )

void

pop_all ( )

void

pop_context ( )

void

push_bgcolor ( Color bgcolor )

void

push_bold ( )

void

push_bold_italics ( )

void

push_cell ( )

void

push_color ( Color color )

void

push_context ( )

void

push_customfx ( RichTextEffect effect, Dictionary env )

void

push_dropcap ( String string, Font font, int size, Rect2 dropcap_margins=Rect2(0, 0, 0, 0), Color color=Color(1, 1, 1, 1), int outline_size=0, Color outline_color=Color(0, 0, 0, 0) )

void

push_fgcolor ( Color fgcolor )

void

push_font ( Font font, int font_size=0 )

void

push_font_size ( int font_size )

void

push_hint ( String description )

void

push_indent ( int level )

void

push_italics ( )

void

push_language ( String language )

void

push_list ( int level, ListType type, bool capitalize, String bullet="•" )

void

push_meta ( Variant data )

void