Flying
Fly in Survival mode with the /ability command, or switch to Creative mode to fly.
Commands
/gamemode creative Creative mode: double-tap the spacebar to fly
/gamemode spectator Spectator mode: fly through blocks
/effect give @s minecraft:levitation 999999 0 true Levitation effect: lifts you up into the air
How it works
By default, you can only fly in Minecraft in Creative and Spectator mode. In Creative, just double-tap the spacebar: you rise into the air and can move freely in every direction. In Survival mode you normally can't fly, but there are a few workarounds. The /ability @s mayfly true command (Bedrock Edition) turns on flying for a player in Survival mode. In Java Edition you can use /gamemode creative, fly up and then go back to Survival with /gamemode survival, though you'll start falling right away. Alternatively, the Levitation effect lifts you up, but it doesn't give you full control over your flight. An elytra with firework rockets is the only way to fly in pure survival. On servers, plugins like EssentialsX (with its /fly command) and CMI are popular: they let admins give players permission to fly in any game mode.
Practical tips
In Creative mode, double-tap the spacebar to start flying.
Shift takes you down and the spacebar takes you up, like a helicopter.
Spectator mode lets you fly through blocks, which is perfect for exploring.
An elytra plus rockets is the only way to fly in pure survival without commands.
Details
Related cheats
Invincibility (god mode)
/gamemode creative Unlimited items
/give @s minecraft:diamond 64 Full health and hunger
/effect give @s minecraft:instant_health 1 255 Diamonds and resources
/give @s minecraft:diamond 64