Canvas is a key component of UI in Unity and Canvas render mode is the key of showing the canvas properly. There are 3 render modes at the moment in the Unity:
Screen Space - Overlay
Display the UI in the whole screen. This is normally most of the 2D games fall into. The size of this render type canvas will be scaled with the size of the game screen, and it is always facing towards players.
Screen Space - Overlay is typically used when UI elements do not need to interact with the scene, such as score displays, health bars, or button prompts. Because the elements are not part of the 3D world, they are not affected by the camera's position or rotation, and they are always visible to the player, regardless of what other objects are in the scene.
Screen Space - Camera
Display the UI in a certain camera with a certain distance. If you have multiple cameras in the game, you can use this type of render mode to show canvas differently.
Appearing in the current scene, like a game object. So you can move the whole canvas around just like other game objects. Some examples are character might have the health bar on the top.
This mode is useful when you want to create UI elements that interact with 3D objects in the scene, such as when you want to display health bars or markers that move along with the objects they represent.
Screen Space - Overlay is used when you want to display UI element on top of the scene, without being affected by the camera's position or rotation, such as scoreboards, pause menus, and pop-up notifications, scores and so on.
Similarly, Screen Space - Camera allows UI elements to be displayed as part of the 3D world, still on top of everything, but The UI elements are positioned relative to a specific camera and will change position and scale based on the camera's movement and perspective.
World space will display the UI elements along with the game object, such as health bar, marker and so on.