Muslims face the Kaaba in Mecca, called the Qibla, to pray together in one direction, as one community. They do not worship the Kaaba or the building; they worship God alone.
The fuller answer
The Kaaba is the first house built for the worship of the one God, built by Prophet Abraham and his son Ishmael. At first, the Prophet ﷺ prayed towards Jerusalem, and then God commanded him to turn towards the Kaaba. A Muslim anywhere in the world turns towards it, so that all Muslims form concentric circles around it.
Facing one direction unites people of every race and language, and for a person who is travelling, it is enough to try one's best to find the direction. This website has a Qibla finder that shows the direction from your location with a compass.
We have certainly seen the turning of your face, [O Muhammad], toward the heaven, and We will surely turn you to a qiblah with which you will be pleased. So turn your face toward al-Masjid al-Haram. And wherever you [believers] are, turn your faces toward it [in prayer]. Indeed, those who have been given the Scripture well know that it is the truth from their Lord. And Allah is not unaware of what they do.
And [mention] when Abraham was raising the foundations of the House and [with him] Ishmael, [saying], "Our Lord, accept [this] from us. Indeed You are the Hearing, the Knowing.
This answer follows the mainstream Sunni understanding and is general learning, not a fatwa. Where Muslims differ, the answer says so. Have a question of your own? Write to us.