Edinburgh's history may be said to have begun when Malcolm III of Scotland erected a castle there in the late 11th cent. and his wife built the Chapel of St. Margaret, the city's oldest surviving building. A town grew up around the castle and was chartered in 1329 by Robert I. It grew steadily despite repeated sacking and burning by the English in the border wars and became the capital city of Scotland in 1437.
James IV was the first monarch to make Edinburgh his regular seat. The rooms of Mary Queen of Scots are preserved in Holyrood Palace. The city lost importance when James VI became king of England in 1603 and commerce and society followed the court to London. After the Act of Union with England in 1707 dissolved the Scottish Parliament, Edinburgh retained the Supreme Courts of Law, which now meet in the old Parliament House.
Edinburgh blossomed as a cultural center in the 18th and 19th cent. around the figures of the philosophers David Hume and Adam Smith and the writers Robert Burns and Sir Walter Scott. The Edinburgh Review, founded in 1802, added to the city's literary reputation. Following voter approval and parliamentary passage of a devolution act, the Scottish Parliament met for the first time in nearly 300 years in Edinburgh in 1999. The new parliament building was completed in 2004.