If you're talking about the movie "300" it was horsesh!t.
But the battle was real. The Persians drawback was that they were a huge army, numbering in the hundreds of thousands, so their intent to conquer Greece necessitated crossing the Hellespont and going down the coast towards Greece, and in Thermopylae lay the only road big enough to channel Xerxes and his army (between the mountains and the sea).
The Greeks knew this and sent Leonidas essentially on a suicide mission, from which there was no return. His only mission was to jam them at the narrow pass to buy time, to allow Athens to be evacuated, and to allow the allied navy to relocate to Salamis.
It's one of the most famous rear-guard action in military history. But unlike myth, there were more than 300.. around 2,000 roughly. However 300 of them were indeed Spartans, and all except 2 or 3 of the Spartans were killed. Legend is that those few were so ashamed to be alive, they all died within the year.