Minecraft Target Selectors Explained (@a @p @e @r @s)

Target selectors are the shorthand that lets a Minecraft command pick who or what it acts on without typing player names. Instead of /tp Steve 100 64 100, you can write /tp @p 100 64 100 and the game resolves the nearest player automatically. This reference covers all six Java Edition selector variables (@p, @r, @a, @e, @s, @n) and every filter argument you can add in square brackets, current for Minecraft Java 26.2.

To run any of these, open the chat window by pressing T (or /, which pre-types the slash) and enter a command. On a multiplayer server you can also type commands into the server console without the leading slash. Cheat commands generally require operator/permission level 2, so make sure cheats are enabled or you are opped. Want to build selectors visually and copy the exact string? Use our free Minecraft Target Selector tool.

The Six Selector Variables at a Glance

SelectorTargetsDefault sort / limitExample
@pNearest player. If tied, the most recently joined player wins.sort=nearest, limit=1tp @p 100 64 100
@rA random online player (Java can target a random entity with type=).sort=random, limit=1give @r diamond 1
@aAll online players, including dead/respawning players.sort=arbitrary, no limitgamemode adventure @a
@eAll alive entities in loaded chunks (players, mobs, items, etc.).sort=arbitrary, no limitkill @e[type=zombie]
@sThe entity that executed the command. Selects nothing if the executor is not an entity.self onlytag @s add marked
@nNearest alive entity of any type, not just players.sort=nearest, limit=1data get entity @n

Players vs Entities: @a @p @r vs @e @n @s

@a, @p and @r always resolve to players. In Java you cannot use type= to make them target a mob — that argument only re-types @e, @n and @s. A key gotcha: @a includes dead players who are still respawning, whereas @e only matches alive entities in loaded chunks. So gamemode adventure @a catches everyone, but @e[type=player] may miss a player mid-respawn.

@e is the broadest selector and almost always needs narrowing. kill @e[type=zombie] removes every zombie, and @e[type=!player] targets every non-player entity. @n is the entity-aware cousin of @p@n[type=cow] is the nearest cow. @s refers only to the command’s executor and is the backbone of /execute chains: it selects nothing from a command block or the bare server console because neither is an entity, but it can select a dead entity.

Selector Arguments (Filters)

Arguments go inside square brackets and are combined with logical AND: @e[type=zombie,distance=..10] means zombies and within 10 blocks. Java is case-sensitive. Many arguments can be negated with ! and repeated for multiple exclusions.

ArgumentSyntaxWhat it filtersExample
typetype= / type=! / type=#Entity type; # for entity-type tag, ! to exclude (one positive value only).@e[type=creeper]
distancedistance=Euclidean distance in blocks. Java ranged floats; cannot be negative.@e[distance=5..15]
limitlimit=Max targets returned, applied after sort.@e[type=item,limit=5]
sortsort=nearest|furthest|random|arbitraryOrder targets are chosen before limit.@a[limit=3,sort=furthest]
x, y, zx=,y=,z=Override the search origin (Java: not center-corrected).@e[x=100,y=64,z=200,distance=..10]
dx, dy, dzdx=,dy=,dz=Cuboid volume by hitbox intersection from the origin.@e[x=0,y=64,z=0,dx=5,dy=3,dz=5]
tagtag= / tag=! / tag=Custom /tag tags; empty matches no tags, ! matches any tag.@e[tag=marked,tag=!done]
scoresscores={=}Scoreboard objective values (integer or range), ANDed.@a[scores={kills=10..}]
nbt (Java only)nbt= / nbt=!Entity NBT match via stringified NBT.@e[type=sheep,nbt={Color:0b}]
gamemodegamemode=survival|creative|adventure|spectatorPlayer game mode, negatable.@a[gamemode=!spectator]
namename= / name=!Exact name (case-sensitive; quote spaces).@e[name="My Dog"]
levellevel=Player experience level.@a[level=30..]
x_rotationx_rotation=Head pitch: -90 up, 0 horizon, +90 down.@e[x_rotation=..0]
y_rotationy_rotation=Yaw: -180 north, -90 east, 0 south, +90 west.@e[y_rotation=-45..45]
team (Java only)team= / team=! / team=Scoreboard team; empty = no team.@a[team=red]
advancements (Java only)advancements={=}Advancement or criterion completion.@a[advancements={story/smelt_iron=true}]
predicate (Java only)predicate= / predicate=!Data-pack predicate match.@e[predicate=mypack:is_underwater]

Sort and Limit: Order Matters

Sort always runs before limit. That is why default limits pair with default sorts: @p and @n use sort=nearest, limit=1; @r uses sort=random, limit=1; @a and @e use sort=arbitrary with no limit (arbitrary is the fastest ordering). Override them together — @e[type=item,limit=5,sort=nearest] returns the five closest dropped items, while @a[limit=3,sort=furthest] returns the three players farthest from the execution point. You cannot raise @s beyond one target.

Position, Distance and Volume

By default a selector searches from the command’s execution position. Override the origin with x, y, z — in Java these are not center-corrected, so x=0 means exactly 0.0. Combine with distance for a sphere (@e[distance=..10] = within 10 blocks) or with dx/dy/dz for a box. The cuboid spans from (x,y,z) to (x+dx, y+dy, z+dz) plus one block, and selection is by hitbox intersection, not entity center. Unspecified d-axes default to 0. For rotation-aware effects, x_rotation filters pitch and y_rotation filters yaw.

Tags, Scores and Data-Driven Filters

For map-making, the most powerful filters are data-driven. tag reads custom tags set with /tag: @e[tag=marked] matches tagged entities, tag= matches entities with no tags, and multiple tag= arguments are ANDed. scores reads scoreboard objectives as ranges — @a[scores={hp=1..5,mana=10}]. Java-only filters include nbt (matches a subset of the entity’s NBT, e.g. @a[nbt={OnGround:true}]), team, advancements, and predicate. Note the nbt selector still reads entity NBT and was unaffected by the 1.20.5 move to item components — that change only altered item syntax like /give, not selector arguments.

How to Run These

  • Chat: Press T or /, type the command with its leading slash (e.g. /kill @e[type=zombie]), and press Enter. Here @s resolves to you.
  • Command block: Place a command block (obtained with /give), enter the command without the slash, and power it. The block is not an entity, so @s selects nothing unless run through /execute as.
  • Server console: Type commands with no leading slash directly into the console. The console has no position or entity, so @p/@e resolve relative to the world spawn context and @s selects nothing.

These selectors underpin nearly every command. See our full Minecraft commands list, the give command guide, the summon command guide, and teleport commands for real-world use. Running a server? XGamingServer Minecraft hosting gives you instant console access to test them.

Java vs Bedrock Differences

The five core variables exist in both editions, and @n (added during the 1.20.5 dev cycle) is available in Java and Bedrock too. The argument spellings differ, however. Java’s distance becomes Bedrock’s r (max) and rm (min); level becomes l/lm; x_rotation becomes rx/rxm; y_rotation becomes ry/rym; and gamemode becomes m (with shorthands s/0, c/1, a/2, d/5).

Bedrock has no sort keyword — it merges limit and sort into c, where a positive value takes the nearest N and a negative value the furthest N. Java-only arguments with no Bedrock equivalent are nbt, team, advancements, predicate and sort. Bedrock-only arguments include family, hasitem, has_property and haspermission. Coordinate handling differs too: Java x/y/z are not center-corrected, while Bedrock center-corrects integer coordinates. Education Edition adds @c and @v (agents), and @initiator exists in Bedrock/Education for NPC dialogue.

Frequently Asked Questions

What is the difference between @a and @e?

@a targets all online players including dead/respawning ones. @e targets all alive entities in loaded chunks — players, mobs, items and more — so it can include players but excludes anyone mid-respawn. Use @e[type=player] only when you specifically want the entity-based view.

Why does @p pick the “most recent” player in a tie?

@p defaults to sort=nearest, limit=1. If two players are exactly equidistant from the execution point, the tie-breaker is the one who joined the server most recently.

Can I target mobs with @p or @r?

Not in Java. @a, @p and @r always resolve to players, and type= cannot change their class. To target the nearest or a random non-player entity, use @n or @e with a type= filter and a sort. (In Java, @r can use type= for a random non-player entity specifically.)

How do I select entities within a specific area?

For a sphere, use distance: @e[distance=..10]. For a box, set an origin with x/y/z and a volume with dx/dy/dz: @e[x=0,y=64,z=0,dx=5,dy=3,dz=5] selects entities whose hitbox intersects that region.

Does @s work in a command block?

No — @s selects nothing when the executor is not an entity, which includes command blocks and the server console. To give a command block an entity executor, run it through /execute as @e[...] run ..., after which @s refers to that entity.

Related guides: target selectors overview, gamerules list, item IDs, keep inventory command, and the Minecraft enchantments list. Build any selector instantly with our Target Selector tool.

Ready to play?

Run your own Minecraft server with XGamingServer

Spin up an always-on Minecraft server your friends can join in minutes — no port-forwarding, no tech headaches.

99.9%Uptime SLA
< 5 minInstant setup
24/7Human support
DDoSProtected
Instant setup Your server is live in minutes with a one-click control panel.
Mods & plugins Install mods, plugins and workshop content in a few clicks.
DDoS protected Enterprise DDoS mitigation keeps your server online 24/7.
Low-latency hardware Premium CPUs & NVMe SSDs for lag-free multiplayer.
Free backups Automatic backups so your world is never lost.
Real human support Gamers helping gamers — 24/7, no bots, no scripts.

Pick your Minecraft plan & play in minutes

See all plans
Starter $8.40/mo 4 GB RAM Renews $12/mo Buy now
Rookie $17.50/mo 8 GB RAM Renews $25/mo Buy now
Pro $24.50/mo 12 GB RAM Renews $35/mo Buy now