Updated:

1. Summon a named mob

/summon zombie ~ ~ ~ {CustomName:"Boss",CustomNameVisible:1b}

CustomNameVisible:1b keeps the name visible from a distance. In Java 1.21.4 and earlier, write CustomName:'"Boss"'. On Bedrock, put the name after the mob type:

/summon zombie Boss ~ ~ ~

2. Rename an existing mob (Java)

/data merge entity @e[type=cow,limit=1,sort=nearest] {CustomName:"Daisy",CustomNameVisible:1b}

See the data command for more.

3. Colored names (Java 1.21.5+)

/summon zombie ~ ~ ~ {CustomName:{text:"Dark Boss",color:"dark_purple",bold:true},CustomNameVisible:1b}

Colors work the same way as colored item names.

4. Pre-named name tag (Java)

/give @s minecraft:name_tag[custom_name="Rex"]

No anvil needed. In Java 1.20.5 to 1.21.4, write custom_name='"Rex"'.

5. Remove a name (Java)

/data remove entity @e[type=cow,limit=1,sort=nearest] CustomName

6. Special names

NameEffect
Dinnerbone or GrummThe mob is upside down
jeb_A sheep cycles through rainbow colors
ToastA rabbit gets a special skin
JohnnyA vindicator attacks other mobs too

Names are case-sensitive.

7. Name every mob of a type (Java)

/execute as @e[type=zombie,distance=..30] run data merge entity @s {CustomName:"Minion",CustomNameVisible:1b}

Every zombie within 30 blocks gets the name. Without distance, every loaded zombie stops despawning, so keep the range small. On 1.21.4 and earlier write CustomName:'"Minion"'.

8. Color names by team

/team add red
/team modify red color red
/team join red @e[type=zombie,limit=1,sort=nearest]

A named mob on a team shows its name in the team color, which helps tell red and blue mobs apart in a mob battle. See the team command.

Troubleshooting

Check your command

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