> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/gum/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flatredball.com/gum/code/standard-visuals/textruntime/bbcode.md).

# BBCode

## Introduction

TextRuntime supports using BBCode-like syntax for formatting individual words and letters. Customizations include changing size, font, and even using custom functions.

Using BBCode for TextRuntimes supports all of the functionality outlined in the Text documentation which can be found here: <https://docs.flatredball.com/gum/gum-tool/gum-elements/text/text#using-bbcode-for-inline-styling>

[Localization](https://docs.flatredball.com/gum/code/localization.md) replaces the whole Text value by its key, so to style part of a localized string, put the BBCode tags inside the translation itself. A Text value that contains `[` is not looked up as a key.

{% hint style="info" %}
`Color`, `Red`, `Green`, `Blue`, `Alpha`, `FontScale`, and `Custom` need no font setup on any runtime.

`Font`, `FontSize`, `IsBold`, `IsItalic`, `OutlineThickness`, `UseFontSmoothing`, and `HasDropshadow` draw text in a different font than the rest of the TextRuntime, so that font has to exist. How it gets made depends on the runtime:

* **MonoGame, KNI, FNA, and raylib** draw with bitmap fonts (`.fnt` files). With [KernSmith](https://docs.flatredball.com/gum/code/files-and-fonts/fonts/font-strategies.md#dynamic-kernsmith-generation), Gum generates the font the first time a tag asks for it, with no extra setup. This is the recommended approach for code-only projects. Without KernSmith, you must provide a pre-built `.fnt` file for each font combination your BBCode text uses. The Gum tool generates these into the FontCache folder when it displays the text. `gumcli fonts` generates the ones used by BBCode tags in the Text values of your project's elements, so a fresh checkout or CI build has them without opening the tool. BBCode text set from code is not in the project, so bake those fonts with the `--font` options of [gumcli fonts](https://docs.flatredball.com/gum/cli/cli/fonts.md).
* [**SkiaSharp-based runtimes**](https://docs.flatredball.com/gum/code/about/runtimes.md) need no font files and no KernSmith. `Font` takes an installed font family, a registered family, or a `.ttf` path, and `IsBold` and `IsItalic` pick the matching style of that family. See [Dynamic Generation on SkiaGum](https://docs.flatredball.com/gum/code/files-and-fonts/fonts/font-strategies.md#dynamic-generation-on-skiagum) and [Bold and Italic on SkiaGum](https://docs.flatredball.com/gum/code/files-and-fonts/fonts/font-strategies.md#bold-and-italic-on-skiagum). `HasDropshadow` is the exception, see below.

For help choosing a font strategy, see the [Fonts hub](https://docs.flatredball.com/gum/code/files-and-fonts/fonts.md).
{% endhint %}

## Code Example: Basic BBCode Styling

The following example shows how to use BBCode tags for inline color and scale changes:

```csharp
// Initialize
var text = new TextRuntime();
text.Text = "This is [Color=Red]red[/Color], [Color=Blue]blue[/Color], and [FontScale=2]big[/FontScale] text";
text.AddToRoot();
```

[Try on XnaFiddle.NET](https://xnafiddle.net/#snippet=H4sIAAAAAAAACkWOTQvCMAyG7_sVoSeF4cCjsoMfODx4mbt1PXQ2zEDXQtdOUfzvdoMphECe5CHvOwFg574IHduAdwHTEZAhT1LTCyNlg3Tg8ekhB4MPuFhjC9lhdFZFwCM6Gsi0qyqelMF46nCx3NZmVCYYvZpVd-ohFj9YbV1eohIOFc-mUaQz3-uAoontv5FGAT9Z4683qTFfi4Zanv2AmLLVbP64U6qypbU-hmDJ5wu5H0Ud4QAAAA)

BBCode tags can be nested and combined. Tags are written as `[TagName=Value]text[/TagName]`. The supported tags include `Color`, `Red`, `Green`, `Blue`, `Alpha` (see [Alpha](#alpha)), `FontScale`, `Font`, `FontSize`, `IsBold`, `IsItalic`, `OutlineThickness`, `UseFontSmoothing` (see [Font Smoothing](#font-smoothing)), `HasDropshadow`, `Custom`, `Glyph` (see [Inline Glyphs](#inline-glyphs)), `Link` (see [Links](#links)), and `State` (see [States](#states)).

Tag names are not case sensitive, and a closing tag matches its opening tag whatever the case, so `[color=Red]red[/COLOR]` works the same as `[Color=Red]red[/Color]`.

An opening tag that has no closing tag is not a tag. It stays in the text and draws as literal characters:

```csharp
// Initialize
var text = new TextRuntime();
// Draws "This is [Color=Red]not closed" with the bracketed text visible.
text.Text = "This is [Color=Red]not closed";
text.AddToRoot();
```

`HasDropshadow` toggles the shadow for just the wrapped run, independently of the TextRuntime's own `HasDropshadow` value. The shadow's offset, blur, and color always come from the TextRuntime's `DropshadowOffsetX`/`DropshadowOffsetY`/`DropshadowBlur`/`DropshadowColor` properties; the tag only controls whether a given run draws it:

```csharp
// Initialize
var text = new TextRuntime();
text.HasDropshadow = true;
text.Text = "This has a shadow, [HasDropshadow=false]this does not[/HasDropshadow], and this does again";
text.AddToRoot();
```

{% hint style="info" %}
`HasDropshadow` toggles the shadow on MonoGame, KNI, FNA, and raylib. On [SkiaSharp-based runtimes](https://docs.flatredball.com/gum/code/about/runtimes.md) the tag is parsed and stripped from the text but has no effect. The shadow always follows the TextRuntime's own `HasDropshadow` value there.
{% endhint %}

## Alpha

The `Alpha` tag sets the opacity of the wrapped text from 0 (invisible) to 255 (opaque). It changes only the alpha channel, so the text keeps its color, the same way `Red`, `Green`, and `Blue` each change one channel. A value outside 0 to 255 is ignored.

```csharp
// Initialize
var text = new TextRuntime();
text.Text = "This is solid, [Alpha=128]this is half faded[/Alpha], and [Color=Red][Alpha=64]this is faded red[/Alpha][/Color]";
text.AddToRoot();
```

{% hint style="info" %}
Available in December 2026, or now if building Gum from source.
{% endhint %}

## Font Smoothing

The `UseFontSmoothing` tag draws the wrapped text with or without antialiasing, independently of the TextRuntime's own `UseFontSmoothing` value. `[UseFontSmoothing=false]` draws the text with hard, pixelated edges.

```csharp
// Initialize
var text = new TextRuntime();
text.Text = "Smooth text and [UseFontSmoothing=false]pixel text[/UseFontSmoothing]";
text.AddToRoot();
```

{% hint style="info" %}
Available in December 2026, or now if building Gum from source.
{% endhint %}

## Inline Glyphs

The `Glyph` tag inserts one character by its code point. Write the code point in decimal (`[Glyph=57344]`) or in hex with a `0x` prefix (`[Glyph=0xE000]`). A code point above U+FFFF, such as an emoji, becomes a surrogate pair. A tag with a value that is not a valid code point is removed from the text.

```csharp
// Initialize
var text = new TextRuntime();
text.Text = "Press [Glyph=0xE000] to jump";
text.AddToRoot();
```

The tag only substitutes the character, so the glyph appears when the font has it. It works the same on every runtime. To draw a picture, embed it in a bitmap font as described in [Custom Glyphs](https://docs.flatredball.com/gum/code/files-and-fonts/fonts/advanced-font-effects.md#custom-glyphs).

{% hint style="info" %}
Available in November 2026, or now if building Gum from source.
{% endhint %}

## Links

The `Link` tag marks a range of text with an id. Gum does not style the range, and the tag is removed from the drawn text. Your code finds the range under a point with `GetTagAtIndex`, which takes a tag name and a character index and returns the tag that contains that character, or `null` if there is none. The index is in the displayed text (BBCode removed), the same index `GetCharacterIndexAtPosition` returns, so the two combine to find the link under the cursor.

The returned `TextTagSpan` has `Name`, `Argument` (the id, such as `shop`), `StartIndex`, and `EndIndex`. `EndIndex` is one past the last character in the tag. `GetCharacterIndexAtPosition` returns the nearest caret position, so a click on the right half of a link's last letter gives `EndIndex` and finds no tag. The tag name is not case sensitive. When tags with the same name are nested, `GetTagAtIndex` returns the innermost one. A tag is only found if it has a closing tag.

The following code shows which link the player clicked in a `Label`. The `Color` tags are optional. They make the links visible:

```csharp
// Class scope
TextRuntime linkText;
Label linkLabel;

// Initialize
linkText = new TextRuntime();
linkText.Text =
    "Visit the [Link=shop][Color=Yellow]shop[/Color][/Link] " +
    "or read the [Link=help][Color=Yellow]help[/Color][/Link].";
linkText.AddToRoot();

linkLabel = new Label();
linkLabel.AddToRoot();
linkLabel.Y = 40;

// Update
GumUI.Update(gameTime);

var cursor = GumUI.Cursor;
if (cursor.PrimaryClick && linkText.HasCursorOver(cursor))
{
    int index = linkText.GetCharacterIndexAtPosition(
        cursor.XRespectingGumZoomAndBounds(),
        cursor.YRespectingGumZoomAndBounds());

    TextTagSpan? link = linkText.GetTagAtIndex("Link", index);
    if (link != null)
    {
        // Argument is "shop" or "help"
        linkLabel.Text = "Clicked " + link.Value.Argument;
    }
}
```

For the index math behind `GetCharacterIndexAtPosition`, see [GetCharacterIndexAtPosition](https://docs.flatredball.com/gum/code/standard-visuals/textruntime/getcharacterindexatposition.md).

{% hint style="info" %}
Available in November 2026, or now if building Gum from source.
{% endhint %}

## States

The `State` tag applies a named state of the TextRuntime to the text it wraps. This lets you define a style once, in the Gum tool's **States** tab or in code, and reuse it by name. Only these variables apply to the wrapped text: `Color`, `Red`, `Green`, `Blue`, `Alpha`, `FontScale`, `Font`, `FontSize`, `OutlineThickness`, `UseFontSmoothing`, `IsBold`, `IsItalic`, `UseCustomFont`, and `HasDropshadow`. Any other variable in the state, such as `X` or `Width`, is skipped. A state name that does not exist is ignored.

The following code defines a `Highlighted` state in code and uses it in a tag:

```csharp
// Initialize
var highlighted = new Gum.DataTypes.Variables.StateSave { Name = "Highlighted" };
highlighted.Variables.Add(new Gum.DataTypes.Variables.VariableSave
{
    Name = "Color",
    Value = System.Drawing.Color.Gold
});
highlighted.Variables.Add(new Gum.DataTypes.Variables.VariableSave
{
    Name = "IsBold",
    Value = true
});

var text = new TextRuntime();
text.AddStates(new System.Collections.Generic.List<Gum.DataTypes.Variables.StateSave> { highlighted });
text.Text = "Plain text with a [State=Highlighted]bold gold run[/State] in it.";
text.AddToRoot();
```

## Text Effects

Six built-in tags animate or recolor the letters they wrap, with no code. They use the names, parameters, and defaults of Godot 4's RichTextLabel effects. Parameters are written after the tag name and separated by spaces, such as `[Wave amp=50 freq=5]`. Every parameter is optional, and a parameter that is missing or not a valid number keeps its default. Tag and parameter names ignore case.

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-5293918c24a968ba07b61d2b54cf1b67d338d05d%2F19_17%2040%2000.png?alt=media" alt=""><figcaption><p>The six text effects</p></figcaption></figure>

| Tag       | Parameters (default)                                  | What it does                                                                                                                            |
| --------- | ----------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| `Wave`    | `amp` (20), `freq` (5)                                | Moves letters up and down in a wave. The offset is `amp / 10` pixels.                                                                   |
| `Shake`   | `rate` (20), `level` (5)                              | Moves each letter in a random direction, `rate` times per second, up to `level / 10` pixels.                                            |
| `Tornado` | `radius` (10), `freq` (1)                             | Moves letters in circles of `radius` pixels.                                                                                            |
| `Fade`    | `start` (0), `length` (10)                            | Fades letters out over `length` letters, starting `start` letters into the tag.                                                         |
| `Rainbow` | `freq` (1), `sat` (0.8), `val` (0.8), `speed` (1)     | Colors letters by a hue that changes along the text and over time.                                                                      |
| `Pulse`   | `color` (white at 25% alpha), `freq` (1), `ease` (-2) | Blends the letters toward their color multiplied by `color`, `freq` times per second. `color` takes the same values as the `Color` tag. |

```csharp
// Initialize
var text = new TextRuntime();
text.Text = "[Wave amp=50 freq=5]Wavy[/Wave], [Shake]shaky[/Shake], [Tornado radius=5]spinning[/Tornado], " +
    "[Fade length=12]fading away[/Fade], [Rainbow]rainbow[/Rainbow], and [Pulse color=Red freq=2]pulsing[/Pulse] text";
text.AddToRoot();
```

Effects combine with other tags. `[Color]` and `[Alpha]` set the color that `Rainbow`, `Pulse`, and `Fade` start from, and typewriter text (`MaxLettersToShow`) reveals effect letters like any other. A `Custom` function inside an effect runs first: the effect's offset adds to the offset the function returns, and `Rainbow`, `Pulse`, and `Fade` change the color the function returns.

Effects animate with the game time passed to `GumUI.Update`, so pausing the game time pauses the effects.

Effect tags need a project at version 9 or later. In a project below version 9, these tags are drawn as plain text. To upgrade, see [Upgrading File (GUMX) Version](https://docs.flatredball.com/gum/gum-tool/upgrading/upgrading-file-gumx-version.md#version-9). Text set from code with no project loaded always uses the effects.

{% hint style="info" %}
Available in December 2026, or now if building Gum from source.
{% endhint %}

## Custom Functions

TextRuntime instances can use the `Custom` tag to define a custom function to be used when rendering a Text. This tag can be used to customize letters in a TextRuntime using custom code, allowing for effects such as wavy, rainbow, or shaking text.

The following variables can be modified on each letter. This list also includes their default values:

* XOffset = 0
* YOffset = 0
* Color = null
* ScaleX = 1
* ScaleY = 1
* RotationDegrees = 0
* ReplacementCharacter = null

To use the Custom tag, the following must be performed:

1. A function must be declared which is of one of the following types:
   * `Func<int, string, LetterCustomization>` - the int value is the index of the letter in the whole displayed text, with all BBCode tags removed. The string represents the text inside the custom block. The returned LetterCustomization instance includes the desired modifications to the letter. Register with `Text.Customizations`.
   * `Func<int, string, LetterCustomization, LetterCustomization>` - same as above, but the third parameter is a LetterCustomization containing the letter's current state (color, offset, scale) as set by prior BBCode tags. This allows relative modifications such as darkening the current color. Register with `Text.ContextCustomizations`.
2. This function must be registered with the `RenderingLibrary.Graphics.Text` type using the appropriate dictionary. On SkiaSharp-based runtimes, register with `SkiaGum.Text` and return a `SkiaGum.LetterCustomization`, which has the same fields. On raylib, use `Gum.Renderables.Text` and `Gum.Renderables.LetterCustomization`.
3. A Custom tag must be included in the text string.

The int index counts displayed characters from the start of the whole text, not from the start of the block. In `"Gold: [Custom=Wave]50[/Custom]"` the function receives 6 for `5` and 7 for `0`, because `Gold:` is six characters. The index is a UTF-16 index with the BBCode tags removed, so an emoji counts as two. The string parameter is only the text inside the block, so its `Length` is the block's length.

### Code Example: Shaking Letters With Custom Tag

The following code block shows how to create a TextRuntime with letters shaking horizontally:

```csharp
// Initialize
LetterCustomization ShakeHorizontally(int index, string textInBlock)
{
    var customization = new LetterCustomization();
    var seconds = DateTime.Now.TimeOfDay.TotalSeconds;
    customization.XOffset = MathF.Sin((float)(seconds * 55 + index * 4));
    return customization;
}
// The function must be registered before it is used
RenderingLibrary.Graphics.Text.Customizations["ShakeHorizontally"] = ShakeHorizontally;

var shakingText = new TextRuntime();
shakingText.AddToRoot();
shakingText.Anchor(Anchor.Center);
shakingText.Text = "I am feeling so [Custom=ShakeHorizontally]cold[/Custom] today!";
```

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-6e6e7eb9adc927fb136fe9c6f488be2872c49514%2F01_05%2056%2054.gif?alt=media" alt=""><figcaption><p>TextRuntime displaying shaking the word "cold"</p></figcaption></figure>

### Code Example: On-Command Custom Values

Custom tags can reference functions inside of classes which can provide additional customization, such as one-time changes.

The following code shows how to make text grow and shrink one time whenever gold is added. First, we create a class that includes the logic for growing/shrinking. This class also stores a StartTime variable which is used to determine the text size. Note that this is using a DateTime for simplicity, but you could also game time or other timing methods.

```csharp
class GrowShrinkCustomFunction
{
    public DateTime StartTime { get; set; } 
    public LetterCustomization Execute(int index, string textInBlock)
    {
        var timeSinceStart = (float)(DateTime.Now - StartTime).TotalSeconds;

        const float growTime = 0.15f;

        float scale = 1;
        float maxScale = 0.5f;
        
        // We only want to change the scale if the time is within the grow/shrink
        // period
        if(timeSinceStart < growTime)
        {
            var ratioGrown = timeSinceStart / growTime;
            scale = 1 + maxScale * ratioGrown;
        }
        else if(timeSinceStart < 2 * growTime)
        {
            var ratioShrunk = (timeSinceStart - growTime) / growTime;
            scale = 1 + maxScale - maxScale * ratioShrunk;
        }

        var customization = new LetterCustomization();
        customization.ScaleX = scale;
        customization.ScaleY = scale;
        return customization;
    }
}
```

We can register this function and use it on a TextRuntime. The following code creates a button which increases the gold and resets the start time:

```csharp
// Class scope
int _gold = 0;
GrowShrinkCustomFunction _growShrink;

// Initialize
_growShrink = new GrowShrinkCustomFunction();
// The function must be registered before it is used
RenderingLibrary.Graphics.Text.Customizations["GrowAndShrink"] = 
    _growShrink.Execute;

var goldDisplayText = new TextRuntime();
goldDisplayText.AddToRoot();
goldDisplayText.Anchor(Anchor.Center);
goldDisplayText.Text = "Gold: [Custom=GrowAndShrink]0[/Custom]";

var button = new Button();
button.Text = "Get Gold!";
button.AddToRoot();
button.Anchor(Anchor.Center);
button.Y += 50;
button.Click += (_, _) =>
{
    _gold += 5;
    goldDisplayText.Text = "Gold: [Custom=GrowAndShrink]" + _gold + "[/Custom]";
    _growShrink.StartTime = DateTime.Now;
};
```

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-a8e2234776598b901c15513f09b9c3aa0f40b02f%2F01_07%2039%2037%20(1).gif?alt=media" alt=""><figcaption><p>Button adding gold and resetting the grow shirnk time.</p></figcaption></figure>

### Code Example: Context-Aware Custom Function

Custom functions can optionally receive the letter's current state as a `LetterCustomization` parameter. This is useful for making relative modifications — for example, darkening whatever color was set by prior BBCode tags.

```csharp
LetterCustomization Darken(int index, string textInBlock, LetterCustomization context)
{
    var color = context.Color ?? System.Drawing.Color.White;
    return new LetterCustomization
    {
        Color = System.Drawing.Color.FromArgb(color.A, color.R / 2, color.G / 2, color.B / 2)
    };
}
RenderingLibrary.Graphics.Text.ContextCustomizations["Darken"] = Darken;

var text = new TextRuntime();
text.AddToRoot();
text.Text = "This is [Color=Red]red and [Custom=Darken]dark red[/Custom][/Color] text";
```

The context parameter includes the current Color, XOffset, YOffset, ScaleX, and ScaleY as resolved by any prior BBCode tags on the same letter. Functions using the simple two-parameter signature continue to work unchanged.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.flatredball.com/gum/code/standard-visuals/textruntime/bbcode.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
