Mary was born at St. James Palace in London on 30 April 1662. Her father was James, Duke of York, and her mother was his first wife, Lady Anne Hyde. She was their oldest daughter. Mary's uncle was Charles II. Her grandfather by her mother's side was Edward Hyde, 1st Earl of Clarendon. He served for a long time as Charles's chief advisor. Her mother gave birth to eight children, but only Mary and her younger sister Anne lived to adulthood.
The Duke of York became a Roman Catholic in 1668 or 1669, but Mary and Anne had a Protestant education, as Charles II had commanded. Mary's mother died in 1671, and her father married again in 1673. He took Mary of Modena, a Catholic, as his second wife. She was also known as Mary Beatrice d'Este. Before her marriage, Mary wrote many letters to Frances Apsley, the daughter of James II's hawks keeper. However, she did not return Mary's interest.
When she was 15, Lady Mary became betrothed to her first cousin, the Protestant William, Prince of Orange. William was the son of Mary, Princess Royal and Prince William II of Nassau. At first, Charles II did not want Mary to marry William. He wanted Mary to marry the heir to the French Throne, the Dauphin Louis, instead. This was because he hoped that England would become friends with France. He also wanted to have a Catholic successor to the throne. But because of Parliament's pressure, he later approved their marriage. He thought that it would make the Protestants like him more, but he was wrong. Mary and William married in London on 4 November 1677. It was reported that Mary wept through the whole ceremony.
Mary went to the Netherlands and lived there as William's wife. The Dutch people liked her because of her lively, friendly nature, and Mary loved William deeply. However, the marriage was often unhappy. Her three pregnancies ended in miscarriage or stillbirth, and Mary was very sad that she did not have a child. Her husband was often cold to her, and he had an affair with Elizabeth Villiers, one of Mary's ladies-in-waiting, for a long time. After some time, though, he grew warmer towards Mary.