Updated:

Basic command

VersionCommand (10 minutes, no particles)
Java/effect give @s minecraft:invisibility 600 0 true
Bedrock/effect @s invisibility 600 0 true

The final true hides the particles. Without it, the swirling particles still give away your position.

Make it last forever (Java 1.19.4+)

/effect give @s minecraft:invisibility infinite 0 true

On older versions use a large number of seconds such as 1000000.

Remove it

VersionCommand
Java/effect clear @s minecraft:invisibility
Bedrock/effect @s clear (removes all effects)

Drinking milk also removes every effect.

Hide armor and held items too

Let teammates see you (Java)

/team add red
/team join red @a[tag=red]
/team modify red seeFriendlyInvisibles true

Teammates then see each other as semi-transparent. See the team command guide.

Invisible mobs and armor stands

Mobs take the same effect: /effect give @e[type=minecraft:zombie,distance=..10] minecraft:invisibility 60 0 true. For Java armor stands, use data instead of an effect so only the equipment shows:

/summon minecraft:armor_stand ~ ~ ~ {Invisible:1b,NoGravity:1b}

Invisible item frames (Java 1.20.5+)

/give @p minecraft:item_frame[entity_data={id:"minecraft:item_frame",Invisible:1b}] 16
/give @p minecraft:glow_item_frame[entity_data={id:"minecraft:glow_item_frame",Invisible:1b}] 16

Frames placed from these items have no visible border, so the item inside looks like it floats on the wall. Effects do not work on item frames because they are not mobs. On 1.20.4 and earlier use item_frame{EntityTag:{Invisible:1b}}.

Things to know

Check your command

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