Updated:

A gold, bold name by version

VersionCommand
Java 1.21.5+/give @p minecraft:diamond_sword[custom_name={text:"Legendary Sword",color:"gold",bold:true,italic:false}]
Java 1.20.5–1.21.4/give @p minecraft:diamond_sword[custom_name='{"text":"Legendary Sword","color":"gold","bold":true,"italic":false}']
Java 1.13–1.20.4/give @p minecraft:diamond_sword{display:{Name:'{"text":"Legendary Sword","color":"gold","bold":true,"italic":false}'}}

Up to 1.21.4 the name is a JSON string wrapped in single quotes. From 1.21.5 you write {text:…} directly. The old form on a new version gives an error or shows the raw {"text":…} as the name.

Color names

NameNameNameName
blackdark_bluedark_greendark_aqua
dark_reddark_purplegoldgray
dark_graybluegreenaqua
redlight_purpleyellowwhite

Since Java 1.16 you can also use any hex color, such as color:"#FF8800". There is no orange or purple.

Remove the italics

custom_name is shown in italics like an anvil rename unless you add italic:false. On 1.20.5+ you can use item_name instead, which is treated as the item's own name: never italic, and replaced if someone renames it on an anvil.

Several colors in one name (1.21.5+)

/give @p minecraft:diamond_sword[custom_name=[{text:"",italic:false},{text:"Legendary ",color:"gold"},{text:"Sword",color:"red",bold:true}]]

A list of parts lets each part have its own style. The first part's settings carry over to the rest, so an empty first part with italic:false removes italics for the whole name.

Colored lore (1.21.5+)

/give @p minecraft:diamond_sword[lore=[{text:"Once wielded by an ancient king",color:"gray",italic:false},{text:"High attack damage",color:"green",italic:false}]]

Each list entry is one line. Lore is purple italic by default. On 1.20.5–1.21.4 wrap each line as a string: '{"text":"…"}'.

Common problems

Check your command

The Command Error Doctor checks common syntax mistakes in your browser.