Dunfermline was a favourite residence of many Scottish monarchs. Documented history of royal residence there begins in the 11th century with Malcolm III who made it his capital. His seat was the nearby Malcolm's Tower, a few hundred yards to the west of the later palace. In the medieval periodDavid II and James I of Scotland were both born at Dunfermline. and pend which link Dunfermline palace and abbey. Dunfermline Palace is attached to the historic Dunfermline Abbey, occupying a site between the abbey and deep gorge to the south. It is connected to the former monastic residential quarters of the abbey via a gatehouse above a pend, one of Dunfermline's medieval gates. The building therefore occupies what was originally the guest house of the abbey. However, its remains largely reflect the form in which the building was remodelled by James IV around 1500.
stayed at Dunfermline Palace in June 1585 to avoid the plague which raged in Edinburgh. He had a proclamation made to regulate the prices of food, drink, and lodgings for his courtiers in Dunfermline town. In 1589 the palace was given as a wedding present by the king to his bride Anne of Denmark. She gave birth to three of their children in the Palace; Elizabeth, Charles and Robert, attended by her German physician, Martin Schöner. The palace staff included the keeper John Gibb, the chamberlain Henry Wardlaw of Pitreavie, the gardener John Lowrie, the plumber James Coupar, who fixed the lead roofs, and Thomas Walwood, foreman of the coal pits. Anne of Denmark had a new building built at the Palace completed in 1600, and known as the "Queen's House", or "Queen Anna of Denmark House". This tall building had a driveway known as a "pend" running through its basement level, replacing an earlier gateway. In November 1601 she prepared a lodging for her daughter Princess Elizabeth, but the princess remained at Linlithgow Palace on the king's orders. After the Union of Crowns in 1603, the removal of the Scottish court to London meant that the building came to be rarely visited by a monarch. Prince Charles stayed at Dunfermline for a year in the care of Alexander Seton, 1st Earl of Dunfermline after his mother had gone to England. Dr Henry Atkins wrote from Dunfermline in July 1604 to Anna of Denmark, saying the Prince, who was slow to learn to walk, could now walk the length of the "great chamber" or "longest chamber" several times daily without a stick. Ten tapestries from the royal tapestry collection were still there in 1616, left from the time the infant Prince Charles resided at the Palace. In 1618 John Taylor, the Water Poet, lodged for a night at the house of the keeper since 1584, John Gibb, which was presumably a part of the palace. Taylor described the site, "the Queenes Palace, a delicate and princely mansion, withall I saw the ruins of an ancient and stately built Abbey, with fair gardens, orchards, meadows, belonging to the Palace."
Charles I returned to Scotland in 1633 for his coronation but only made a brief visit to his place of birth. The last monarch to occupy the palace was Charles II who stayed at Dunfermline in 1650 just before the Battle of Pitreavie. Anne Halkett described meeting him there. Soon afterwards, during the of Scotland, the building was abandoned and by 1708 it had been unroofed. All that remains of the palace today is the kitchen, its cellars, and the impressive south wall with a commanding prospect over the Firth of Forth to the south.