Mary wielded less power than William when he was in England, ceding most of her authority to him, though he heavily relied on her. She did, however, act alone when William was engaged in military campaigns abroad, proving herself to be a powerful, firm, and effective ruler.
Mary, born at St James's Palace in London on 30 April 1662, was the eldest daughter of the Duke of York (the future King James II & VII), and his first wife, Anne Hyde. Mary's uncle was King Charles II, who ruled the three kingdoms of England, Scotland and Ireland; her maternal grandfather, Edward Hyde, 1st Earl of Clarendon, served for a lengthy period as Charles's chief advisor. She was baptised into the Anglican faith in the Chapel Royal at St James's, and was named after her ancestor, Mary, Queen of Scots. Her godparents included her father's cousin, Prince Rupert of the Rhine. Although her mother bore eight children, all except Mary and her younger sister Anne died very young, and King Charles II had no legitimate children. Consequently, for most of her childhood, Mary was second in line to the throne after her father.
The Duke of York converted to Roman Catholicism in 1668 or 1669 and the Duchess about eight years earlier, but Mary and Anne were brought up as Anglicans, pursuant to the command of Charles II. They were moved to their own establishment at Richmond Palace, where they were raised by their governess Lady Frances Villiers, with only occasional visits to see their parents at St James's or their grandfather Lord Clarendon at Twickenham. Mary's education, from private tutors, was largely restricted to music, dance, drawing, French, and religious instruction. Her mother died in 1671, and her father remarried in 1673, taking as his second wife Mary of Modena, a Catholic who was only four years older than Mary.
From about the age of nine until her marriage, Mary wrote passionate letters to an older girl, Frances Apsley, the daughter of courtier Sir Allen Apsley. In time, Frances became uncomfortable with the correspondence, and replied more formally. At the age of fifteen, Mary became betrothed to her cousin, the Protestant Stadtholder of Holland, William III of Orange. William was the son of the King's late sister, Mary, Princess Royal, and thus fourth in the line of succession after James, Mary, and Anne. At first, Charles II opposed the alliance with the Dutch ruler—he preferred that Mary wed the heir to the French throne, the Dauphin Louis, thus allying his realms with Catholic France and strengthening the odds of an eventual Catholic successor in Britain; but later, under pressure from Parliament and with a coalition with the Catholic French no longer politically favourable, he approved the proposed union. The Duke of York agreed to the marriage, after pressure from chief minister Lord Danby and the King, who incorrectly assumed that it would improve James's popularity among Protestants. When James told Mary that she was to marry her cousin, "she wept all that afternoon and all the following day".
William and a tearful Mary were married in St James's Palace by Bishop Henry Compton on 4 November 1677. Mary accompanied her husband on a rough sea crossing back to the Netherlands later that month, after a delay of two weeks caused by bad weather. Rotterdam was inaccessible because of ice, and they were forced to land at the small village of Ter Heijde, and walk through the frosty countryside until met by coaches to take them to Huis Honselaarsdijk. On 14 December, they made a formal entry to The Hague in a grand procession.