Updated:

The basic form

GoalCommand
Add a tag/tag @s add player
Remove it/tag @s remove player
List tags/tag @s list

Same on Java and Bedrock. Tag names cannot contain spaces; letters and numbers are safest.

Select by tag

/effect give @a[tag=player] minecraft:speed 30 1
/tp @a[tag=!player] 0 64 0

[tag=name] picks entities with the tag; [tag=!name] picks those without it. The first line speeds up participants, the second sends everyone else to spawn.

Minigame sign-up

/tag @a[distance=..5] add player
/give @a[tag=player] minecraft:wooden_sword
/tag @a remove player

Tag everyone near the sign-up point, give only them equipment, and remove the tag when the game ends. Tags never expire on their own.

Combine tags

/effect give @a[tag=player,tag=!out] minecraft:glowing 10 0

Several tag= conditions must all match: this highlights participants who are not out yet. Mark eliminated players with /tag @s add out.

Run something once per player

execute as @a[tag=!welcomed] run tellraw @s {"text":"Welcome!","color":"gold"}
tag @a[tag=!welcomed] add welcomed

In a repeating block followed by a chain block, each new player gets the message once and is then tagged. The same pattern works for first-join rewards.

Tag mobs when you summon them

VersionCommand
Java/summon minecraft:zombie ~ ~ ~ {Tags:["boss"]}
Bedrock/summon zombie ~ ~ ~ then /tag @e[type=zombie,c=1] add boss

Afterwards /kill @e[tag=boss] targets only that mob.

Common problems

Check your command

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