The hogwarts express (pottermore.com)
As we know from early historical accounts, and from the evidence of early woodcuts and engravings, Hogwarts students used to arrive at school in any manner that caught their fancy. Some rode broomsticks (a difficult feat when carrying trunks and pets); others commandeered enchanted carts and, later, carriages; some attempted to Apparate (often with disastrous effects, as the castle and grounds have always been protected with Anti-Apparition Charms), others rode a variety of magical creatures.
In spite of the accidents attendant on these various modes of magical transport, not to mention the annual Muggle sightings of vast numbers of airborne wizards travelling northwards, it remained the responsibility of parents to convey their children to school, right up until the imposition of the International Statute of Secrecy in 1692. At this point, it became a matter of urgency to find some more discreet method of transporting hundreds of wizarding children from all over Britain to their secret school in the Highlands of Scotland.
Portkeys were therefore arranged at collecting points all over Britain. The logistics caused problems from the start. Up to a third of students would fail to arrive every year, having missed their time slot, or been unable to find the unobtrusive enchanted object that would transport them to their school. There was also the unfortunate fact that many children were (and are) 'Portkey-sick', and the hospital wing was frequently full to bursting for the first few days of every year, while susceptible students overcame their hysterics and nausea.
While admitting that Portkeys were not an ideal solution to the problem of school transportation, the Ministry of Magic failed to find an acceptable alternative. A return to the unregulated travel of the past was impossible, and yet a more secure route into the school (for instance, permitting a fireplace that might be officially entered by Floo powder) was strongly resisted by successive Headmasters, who did not wish the security of the castle to be breached.
A daring and controversial solution to the thorny problem was finally suggested by Minister for Magic Ottaline Gambol, who was much intrigued by Muggle inventions and saw the potential in trains. Where exactly the Hogwarts Express came from has never been conclusively proven, although it is a fact that there are secret records at the Ministry of Magic detailing a mass operation involving one hundred and sixty-seven Memory Charms and the largest ever mass Concealment Charm performed in Britain. The morning after these alleged crimes, a gleaming scarlet steam engine and carriages astounded the villagers of Hogsmeade (who had also not realised they had a railway station), while several bemused Muggle railway workers down in Crewe spent the rest of the year grappling with the uncomfortable feeling that they had mislaid something important.
The Hogwarts Express underwent several magical modifications before the Ministry approved it for school use. Many pure-blood families were outraged at the idea of their children using Muggle transport, which they claimed was unsafe, insanitary and demeaning; however, as the Ministry decreed that students either rode the train or did not attend school, the objections were swiftly silenced.