Text component format
The text component format, historically also known as raw JSON text, is used by Minecraft to send and display rich-text to players. It can also be sent by players themselves using commands (such as /tellraw
and /title
) and data packs.
Java Edition[edit | edit source]
Text components are written in SNBT, for example {text: "Hello world"}
. They are used for rich-text formatting in written books, signs, custom names and the /tellraw
, /title
, /bossbar
, /scoreboard
and /team
commands.
The format is made up of text components. There is a single root component, which can have child components, which can have their own children and so on. Components can also have formatting and interactivity added to them, which is inherited by their children.
A component can be a [String] string, [NBT List / JSON Array] list or a [NBT Compound / JSON Object] object. Strings and lists are both shorthand for longer object structures, as described below.
- [String] A string containing plain text to display directly. This is the same as an object that only has a [String] text tag. For example,
"A"
and{text: "A"}
are equivalent. - [NBT List / JSON Array] A list of components. Same as having all components after the first one appended to the first's [NBT List / JSON Array] extra list. For example,
["A", "B", "C"]
is equivalent to{text: "A", extra: ["B", "C"]}
. Note that because the later components are actually children of the first one, any formatting applied to the first component is inherited by the later ones. For example,[{text: "A", color: "red"}, "B", "C"]
will display all three letters with red text. - [NBT Compound / JSON Object] A text component object. All non-content tags are optional.
- Content
- [String] type: Optional. Specifies the content type. One of
"text"
,"translatable"
,"score"
,"selector"
,"keybind"
, or"nbt"
. - If [String] type is not present, has an invalid value, or if the required tags for the specified type are not present, the type is determined automatically by checking the object for the following tags: [String] text, [String] translate, [NBT Compound / JSON Object] score, [String] selector, [String] keybind, and finally [String] nbt. If multiple are present, whichever one comes first in that list is used.
- Values specific to each content type are described below.
- [String] type: Optional. Specifies the content type. One of
- Children
- [NBT List / JSON Array] extra: A list of additional components to be displayed after this one.
- A child text component. Child text components inherit all formatting and interactivity from the parent component, unless they explicitly override them.
- [NBT List / JSON Array] extra: A list of additional components to be displayed after this one.
- Formatting
- [String] color: Optional. Changes the color to render the content in the text component object and its child objects. If not present, the parent color will be used instead. The color is specified as a color code or as a color name.
"#<hex>"
, where<hex>
is a 6-digit hexadecimal color, changes the color to #<hex>"black"
changes the color to
#000000"dark_blue"
changes the color to
#0000AA"dark_green"
changes the color to
#00AA00"dark_aqua"
changes the color to
#00AAAA"dark_red"
changes the color to
#AA0000"dark_purple"
changes the color to
#AA00AA"gold"
changes the color to
#FFAA00"gray"
changes the color to
#AAAAAA"dark_gray"
changes the color to
#555555"blue"
changes the color to
#5555FF"green"
changes the color to
#55FF55"aqua"
changes the color to
#55FFFF"red"
changes the color to
#FF5555"light_purple"
changes the color to
#FF55FF"yellow"
changes the color to
#FFFF55"white"
changes the color to
#FFFFFF
- [String] font: Optional. The resource location of the font for this component in the resource pack within
assets/<namespace>/font
. Defaults to"minecraft:default"
. - [Boolean] bold: Optional. Whether to render the content in bold.
- [Boolean] italic: Optional. Whether to render the content in italics. Note that text that is italicized by default, such as custom item names, can be unitalicized by setting this to
false
. - [Boolean] underlined: Optional. Whether to underline the content.
- [Boolean] strikethrough: Optional. Whether to strikethrough the content.
- [Boolean] obfuscated: Optional. Whether to render the content obfuscated.
- [Int] shadow_color: The color and opacity of the shadow. If omitted, the shadow is 75% the brightness of the text color and 25% the opacity[verify]. Color codes are the hex code of the color converted to a decimal number, or can be calculated from the red, green and blue components using this formula:
Red<<16 + Green<<8 + Blue - [NBT List / JSON Array] shadow_color: Another format. A list containing 4 floats corresponding to red, green, blue, and opacity values as a fraction (ranged 0 to 1, inclusive) that is automatically converted to the int format.
- [String] color: Optional. Changes the color to render the content in the text component object and its child objects. If not present, the parent color will be used instead. The color is specified as a color code or as a color name.
- Interactivity
- [String] insertion: Optional. When the text is shift-clicked by a player, this string is inserted in their chat input. It does not overwrite any existing text the player was writing. This only works in chat messages.
- [NBT Compound / JSON Object] click_event: Optional. Allows for events to occur when the player clicks on text. Only work in chat messages and written books, unless specified otherwise.
- [String] action: The action to perform when clicked. Valid values are:
"open_url"
: Opens the specified URL in the user's default web browser."open_file"
: Opens the specified file on the user's computer. This is used in messages automatically generated by the game (e.g., on taking a screenshot) and cannot be used by players for security reasons."run_command"
: Works in signs, but only on the root text component, not on any children. Activated by using the sign. In chat and written books, this enters the specified command in chat as though the player typed it themselves and pressed enter. However, this can only be used to run commands that do not send chat messages directly (like/say
,/tell
, and/teammsg
). Since they are being run from chat, the player must have the required permissions. In signs, the command is run by the server at the sign's location, with the player who used the sign as the command executor (that is, the entity selected by@s
). Since they are run by the server, sign commands have the same permission level as a command block instead of using the player's permission level, and are not restricted by chat length limits. The command does not need to be prefixed with a "/" slash."suggest_command"
: Opens chat and fills in the specified text or command. If a chat message was already being composed, it is overwritten. This does not work in books.[1]"change_page"
: Can only be used in written books. Changes to the specified page if that page exists."copy_to_clipboard"
: Copies the specified text to the clipboard.
- Additional fields:
- If action is set to
"open_url"
:
- [String] url: The URL to open.
- If action is set to
"open_file"
:
- If action is set to
- [String] path: The file to open.
- If action is set to
"run_command"
:
- If action is set to
- [String] command: The command to run.
- If action is set to
"suggest_command"
:
- If action is set to
- [String] command: The command to fill in chat. Also works with normal texts.
- If action is set to
"change_page"
:
- If action is set to
- [Int] page: The page to change to.
- If action is set to
"copy_to_clipboard"
:
- If action is set to
- [String] value: The text to copy.
- [String] action: The action to perform when clicked. Valid values are:
- [NBT Compound / JSON Object] hover_event: Optional. Allows for a tooltip to be displayed when the player hovers their mouse over text.
- [String] action: The type of tooltip to show. Valid values are:
"show_text"
: Shows a text component."show_item"
: Shows the tooltip of an item as if it was being hovering over it in an inventory."show_entity"
: Shows an entity's name, type, and UUID. Used by [String] selector.
- If action is set to
"show_text"
:
- [String][NBT List / JSON Array][NBT Compound / JSON Object] value: Another text component. Can be any valid text component type: string, list, or object. Note that [NBT Compound / JSON Object] click_event and [NBT Compound / JSON Object] hover_event do not function within the tooltip.
- If action is set to
"show_item"
:
- If action is set to
- The item stack whose tooltip that should be displayed.
- [String] id: The item's resource location. Defaults to
minecraft:air
if invalid. - [Int] count: Optional. Size of the item stack. This typically does not change the content tooltip.
- [NBT Compound / JSON Object] components: Optional. Additional information about the item. See Data component format.
- If action is set to
"show_entity"
:
- [NBT Compound / JSON Object] name: Optional. Hidden if not present. A text that is displayed as the name of the entity.
- [String] id: A string containing the type of the entity, as a resource location.
- [String][NBT List / JSON Array] uuid: The UUID of the entity. Either:
- A string representing the UUID in the hyphenated hexadecimal format. Must be a valid UUID.
- A list of four numbers representing the UUID in int-array format. e.g.
[I;1,1,1,1]
.
- [String] id: The item's resource location. Defaults to
- [String] action: The type of tooltip to show. Valid values are:
- Content
Due to the [NBT List / JSON Array] extra tag, the above format may be recursively nested to produce complex and functional text strings. However, a text component doesn't have to be complicated at all: virtually all properties are optional and may be left out.
Content types[edit | edit source]
Text components can display several types of content. These tags should be included directly into the text component object.
Plain Text[edit | edit source]
Displays plain text.
- [NBT Compound / JSON Object] The text component.
- [String] type: Optional. Set to
"text"
. - [String] text: A string containing plain text to display directly.
- [String] type: Optional. Set to
Translated Text[edit | edit source]
Displays a translated piece of text from the currently selected language. This uses the client's selected language, so if players with their games set to different languages are logged into the same server, each will see the component in their own language.
Translations are defined in language files in resource packs, including the built-in resource pack.
Translations can contain slots for text that is not known ahead of time, such as player names. When displaying the translated text, slots will be filled from a provided list of text components. The slots are defined in the language file, and generally take the form %s
(displays the next component in the list), or %3$s
(displays the third component in the list; replace 3
with whichever index is desired).[note 1] For example, the built-in English language file contains the translation "chat.type.advancement.task": "%s has made the advancement %s",
.
- [NBT Compound / JSON Object] The text component.
- [String] type: Optional. Set to
"translatable"
. - [String] translate: A translation identifier, corresponding to the identifiers found in loaded language files. Displayed as the corresponding text in the player's selected language. If no corresponding translation can be found, the identifier itself is used as the translated text.
- [String] fallback: Optional. If no corresponding translation can be found, this is used as the translated text. Ignored if [String] translate is not present.
- [NBT List / JSON Array] with: Optional. A list of text components to be inserted into slots in the translation text. Ignored if [String] translate is not present.
- A text component. If no component is provided for a slot, the slot is displayed as no text.
- [String] type: Optional. Set to
Scoreboard Value[edit | edit source]
Displays a score from the scoreboard.
[show]Requires component resolution. |
---|
This component is resolved into a [String] text component containing the scoreboard value. |
- [NBT Compound / JSON Object] The text component.
- [String] type: Optional. Set to
"score"
. - [NBT Compound / JSON Object] score: Displays a score holder's current score in an objective. Displays nothing if the given score holder or the given objective do not exist, or if the score holder is not tracked in the objective.
- [String] name: The name of the score holder whose score should be displayed. This can be a selector like @p or an explicit name. If the text is a selector, the selector must be guaranteed to never select more than one entity, possibly by adding
limit=1
. If the text is"*"
, it shows the reader's own score (for example,/tellraw @a {score: {name: "*", objective: "obj"}}
shows every online player their own score in the "obj" objective).[note 2] - [String] objective: The internal name of the objective to display the player's score in.
- [String] name: The name of the score holder whose score should be displayed. This can be a selector like @p or an explicit name. If the text is a selector, the selector must be guaranteed to never select more than one entity, possibly by adding
- [String] type: Optional. Set to
Entity Names[edit | edit source]
Displays the name of one or more entities found by a selector.
If exactly one entity is found, the entity's name is displayed by itself. If more are found, their names are displayed in the form "Name1, Name2, Name3", with gray commas. If none are found, the component is displayed as no text.
Hovering over a name shows a tooltip with the name, type, and UUID of the target. Clicking a player's name suggests a command to whisper to that player. Shift-clicking a player's name inserts that name into chat. Shift-clicking a non-player entity's name inserts its UUID into chat.
[show]Requires component resolution. |
---|
|
- [NBT Compound / JSON Object] The text component.
- [String] type: Optional. Set to
"selector"
. - [String] selector: A string containing a selector.
- [NBT Compound / JSON Object] separator: Optional, defaults to
{color: "gray", text: ", "}
. A text component. Used as the separator between different names, if the component selects multiple entities.
- [String] type: Optional. Set to
Keybind[edit | edit source]
Displays the name of the button that is currently bound to a certain configurable control. This uses the client's own control scheme, so if players with different control schemes are logged into the same server, each will see their own keybind.
- [NBT Compound / JSON Object] The text component.
- [String] type: Optional. Set to
"keybind"
. - [String] keybind: A keybind identifier, to be displayed as the name of the button that is currently bound to that action. For example,
{keybind: "key.inventory"}
displays "e" if the player is using the default control scheme.
- [String] type: Optional. Set to
NBT Values[edit | edit source]
Displays NBT values from entities, block entities, or command storage.
NBT strings display their contents. Other NBT values are displayed as SNBT, with no spacing between symbols. If [Boolean] interpret is set to true, the game will instead attempt to parse and display that text as its own text component. That only works on compounds and lists which contain tags with the proper key names. If [Boolean] interpret is true and parsing fails, the component is displayed as no text, or if it directs to a string, shows the string itself. If more than one NBT value is found, either by selecting multiple entities or by using a multi-value path, they are displayed in order, with the [Undefined] separator value between them.
[show]Requires component resolution. |
---|
|
- [NBT Compound / JSON Object] The text component.
- [String] type: Optional. Set to
"nbt"
. - [String] source: Optional. Allowed values are
"block"
,"entity"
, and"storage"
, corresponding to the source of the NBT data. - [String] nbt: The NBT path used for looking up NBT values from an entity, block entity, or storage. Requires one of [String] block, [String] entity, or [String] storage. Having more than one is allowed, but only one is used.[note 3]
- [Boolean] interpret: Optional, defaults to false. If true, the game attempts to parse the text of each NBT value as a text component. Ignored if [String] nbt is not present.
- [NBT Compound / JSON Object] separator: Optional, defaults to
{text: ", "}
. A text component. Used as the separator between different tags, if the component selects multiple tags. - [String] block: A string specifying the coordinates of the block entity from which the NBT value is obtained. The coordinates can be absolute, relative, or local. Ignored if [String] nbt is not present.
- [String] entity: A string specifying the target selector for the entity or entities from which the NBT value is obtained. Ignored if [String] nbt is not present.
- [String] storage: A string specifying the resource location of the command storage from which the NBT value is obtained. Ignored if [String] nbt is not present.
- [String] type: Optional. Set to
Component resolution[edit | edit source]
Certain text content types ([NBT Compound / JSON Object] score, [String] selector, and [String] nbt) do not work in all contexts. These content types need to be resolved, which involves retrieving the appropriate data from the world, rendering it into "simple" text components, and replacing the "advanced" text component with that. This resolution can be done by signs, by written books when they are first opened, by boss bar names, by text displays, and by commands such as /tellraw
and /title
. It can also be done by the item modifers set_name and set_lore, but only if their [String] entity tag is set. Custom item names, custom entity names and scoreboard objective names cannot by themselves resolve these components.
Additionally, resolution fixes a single value in place. Therefore, these content types are not dynamic, and don't update to reflect changes in their environment, while "simple" components usually do.
Bedrock Edition[edit | edit source]
Unlike Java Edition, text components in Bedrock Edition are written in JSON.
- [NBT Compound / JSON Object] The root tag.
- [NBT List / JSON Array] rawtext: A list contains all text object.
- [NBT Compound / JSON Object] To be valid, an object must contain one content tag: [String] text, [String] translate, [NBT Compound / JSON Object] score, or [String] selector. Having more than one is allowed, but only one is used.[note 4]
- Content: Plain Text
- [String] text: A string containing plain text to display directly.
- Content: Translated Text
- [String] translate: A translation identifier, to be displayed as the corresponding text in the player's selected language. If no corresponding translation can be found, the identifier itself is used as the translation text. This identifier is the same as the identifiers found in lang files from assets or resource packs.
- [NBT List / JSON Array] with: Optional. A list of text component arguments to be inserted into slots in the translation text. Ignored if [String] translate is not present.
- Translations can contain slots for text that is not known ahead of time, such as player names. These slots are defined in the translation text itself, not in the text component, and generally take the form
%%1
(displays the first argument; replace1
with whichever index is desired). If no argument is provided for a slot, the slot is not displayed.
- Translations can contain slots for text that is not known ahead of time, such as player names. These slots are defined in the translation text itself, not in the text component, and generally take the form
- Content: Scoreboard Value (requires resolution)
- [NBT Compound / JSON Object] score: Displays a score holder's current score in an objective. Displays nothing if the given score holder or the given objective do not exist, or if the score holder is not tracked in the objective.
- [String] name: The name of the score holder whose score should be displayed. This can be a selector like @p or an explicit name. If the text is
"*"
, it shows the reader's own score (for example,/tellraw @a { "rawtext" : [ { "score" : { "name" : "*" , "objective" : "obj"} } ] }
shows every online player their own score in the "obj" objective).[note 5] - [String] objective: The internal name of the objective to display the player's score in.
- [String] name: The name of the score holder whose score should be displayed. This can be a selector like @p or an explicit name. If the text is
- Content: Entity Names (requires resolution)
- [String] selector: A string containing a selector. Displayed as the name of the player or entity found by the selector. If more than one player or entity is found by the selector, their names are displayed in either the form "Name1 and Name2" or the form "Name1, Name2, Name3, and Name4". Hovering over a name shows a tooltip with the name, type, and UUID of the target. Clicking a player's name suggests a command to whisper to that player. Shift-clicking a player's name inserts that name into chat. Shift-clicking a non-player entity's name inserts its UUID into chat.
- [NBT Compound / JSON Object] To be valid, an object must contain one content tag: [String] text, [String] translate, [NBT Compound / JSON Object] score, or [String] selector. Having more than one is allowed, but only one is used.[note 4]
- [NBT List / JSON Array] rawtext: A list contains all text object.
- Basic raw text example
/tellraw @a { "rawtext" : [ { "text" : "Hello world" } ] }
This sends a message to all players saying "Hello World" in English only. See the Translate action to see how to send localized texts.
Appending[edit | edit source]
Raw text takes in an array of text objects. Each object in the list is added to the previous object. For example, /tellraw @a { "rawtext" : [ { "text":"Hello" }, { "text" : " World" } ] }
outputs the same "Hello World" as the first example. Appending text can be useful to combine 2 different localized texts, or apply different colors to each word etc.
Breaking lines[edit | edit source]
You can go down a line by using "\n". For example,
/tellraw @a { "rawtext" : [ { "text" : "Hello\nNext line" } ] }
Translate[edit | edit source]
The translate object allows creators to provide localized text to users. If translate is specified along with text, translate overrides the text object. The string to provide to translate is the name of the string in the language files. For example, in Vanilla Minecraft "commands.op.success" is the string that displays when /op is used on a player successfully.
/tellraw @a { "rawtext": [ { "translate" : "commands.op.success" } ] }
This outputs "Opped %s" to all players. Note that because of text being ignored with translate specified, the following example outputs the same text:
/tellraw @a { "rawtext" : [ { "text":"Hello World", "translate":"commands.op.success" } ] }
With[edit | edit source]
In the translate example above, it outputs "Opped %s". To have a name or other text show up instead of %s, "with" needs to be specified as well. Note that "with" only works with "translate" and also requires an array []
instead of curly brackets {}
.
/tellraw @a { "rawtext": [ { "translate" : "commands.op.success", "with": [ "Steve" ] } ] }
If you want to use a translated text inside the "with" component, instead of an array it needs to be another rawtext component (which consists of an array of text components). The following example outputs "Opped Apple".
/tellraw @a { "rawtext": [ { "translate" : "commands.op.success", "with": { "rawtext": [ { "translate" : "item.apple.name" } ] } } ] }
%%s[edit | edit source]
"translate" and "%s" can be used without needing a corresponding string in the localization files. For example:
/tellraw @a { "rawtext": [ { "translate" : "Hello %%s", "with": [ "Steve" ] } ] }
This outputs "Hello Steve" to all players.
Multiple %s[edit | edit source]
%%s can be used multiple times. They are filled in, in the order specified
/tellraw @a { "rawtext": [ { "translate" : "Hello %%s and %%s", "with": [ "Steve", "Alex" ] } ] }
Outputs: "Hello Steve and Alex"
You can again use a rawtext component to replace the plain string array, like so
/tellraw @a { "rawtext": [ { "translate" : "Hello %%s and %%s", "with": { "rawtext" : [ { "text" : "Steve" }, { "translate" : "item.apple.name" } ] } } ] }
Outputs: "Hello Steve and Apple"
Ordering with %%#[edit | edit source]
The order to fill in %s to be filled in can be changed by instead specifying it with %%#, replacing # with an actual number. For example, to swap the position of Steve and Alex in the above example, instead run the following:
/tellraw @a { "rawtext" : [ {"translate" : "Hello %%2 and %%1", "with": [ "Steve", "Alex"] } ] }
Outputs: "Hello Alex and Steve"
Formatting[edit | edit source]
String formatting is still possible, but not using the text component format used in Java Edition. Instead, formatting codes are used to change text color and style.
History[edit | edit source]
[hide]Java Edition | |||||||
---|---|---|---|---|---|---|---|
1.7.2 | 13w37a | Added /tellraw , which supports raw JSON text. | |||||
1.8 | 14w02a | Added text component insertion . | |||||
14w07a | Added text component score . | ||||||
14w20a | Added /title , which supports raw JSON text.
| ||||||
Added text component selector . | |||||||
14w25a | Now supported by signs and written books. | ||||||
1.12 | 17w16a | Added text component keybind . | |||||
1.13 | 18w01a | Now supported by custom entity names. | |||||
18w05a | Added /bossbar . The argument <name> supports raw JSON text. | ||||||
pre8 | Now supported by scoreboard objective names and team names. | ||||||
1.14 | 18w43a | Added text component nbt with block and entity .
| |||||
Now supported by the item tag Lore . | |||||||
18w44a | Added text component interpret . | ||||||
1.15 | 19w39a | Added storage for the nbt text component. | |||||
19w41a | Added the action copy_to_clipboard for the text component clickEvent . | ||||||
1.16 | 20w17a | Added text component font .
| |||||
Added argument contents for hoverEvent , replacing value , which is now deprecated but still supported.
| |||||||
The color component can now contain a hexadecimal RGB value prefixed by # (Example: "color":"#ff0088" ). | |||||||
1.19.4 | 23w03a | Added text component fallback . | |||||
1.20.3 | 23w40a | Added text component type .
| |||||
contents.id field in show_entity can represent the UUID as an array of ints.
| |||||||
Numbers and booleans are no longer auto-converted to strings, and so are invalid for the text component.
| |||||||
Several errors that used to be ignored are now hard errors. | |||||||
23w42a | Changes to chat component serialization: components of type nbt now have source field with allowed values: entity , block , and storage . | ||||||
1.21.2 | 24w33a | Invalid selector patterns in chat components will now cause commands to fail to parse, instead of resolving to an empty string. | |||||
1.21.4 | 24w44a | Added optional shadow_color style field to Text Components, which overrides the shadow properties of text. | |||||
1.21.5 | 25w02a | Text components are now stored as NBT and are passed into commands using SNBT. | |||||
The hoverEvent field has been renamed to hover_event .
| |||||||
The clickEvent field has been renamed to click_event .
| |||||||
25w03a | The text field in show_text action has been renamed to value . | ||||||
[hide]Bedrock Edition | |||||||
1.9.0 | beta 1.9.0.0 | Added /tellraw , the raw JSON text used to support this command. | |||||
1.16.100 | beta 1.16.100.55 | Added text component score and selector . |
See also[edit | edit source]
External links[edit | edit source]
Notes[edit | edit source]
- ↑ Selecting the "next" argument ignores slots that specify an index explicitly. So if the translation text "Hello %s, %2$s, and %s." was given the components "John" and "Becky", it would display "Hello John, Becky, and Becky."
- ↑ Showing the reader's own score only works in situations where a message has one singular reader. That is chat messages,
/title
s, and written books. It does not work for bossbar display names or blocks like signs. - ↑ If [String] source is left unspecified, NBT sources are checked in the order [String] entity, [String] block, [String] storage. If multiple are present, whichever one comes first in that list is used.
- ↑ Content tags are checked in the order [String] translate, [String] text, [String] selector, [NBT Compound / JSON Object] score. If multiple are present, whichever one comes first in that list is used.
- ↑ Showing the reader's own score only works in situations where a message has one singular reader. That is chat messages,
/titleraw
s, and written books.[verify] It doesn't work for things like signs that can have more than one "reader".[verify]