Family matters
On 6 May 1680, Charles married Ulrika Eleonora of Denmark (1656–1693), daughter of King Frederick III of Denmark (1609–1670). He had previously been engaged to his cousin, Juliana of Hesse-Eschwege, but the engagement was broken after a scandal. Charles and Ulrika were engaged in 1675 in an attempt to smooth over longstanding hostilities, but the Scanian War soon broke out. During the war, Ulrika Eleonora gained a reputation for loyalty to her future home country by exhibiting kindness to Swedish prisoners: she pawned her jewelry, even her engagement ring, to care for the Swedish prisoners of war. Her personal merits and continued charitable acts throughout her tenure endeared her to the Swedish people and eased some of the difficulties brought on by her Danish background. In the peace negotiations between Sweden and Denmark in 1679, the marriage between her and Charles XI was on the agenda, and ratified on 26 September 1679. They married at Skottorp on 6 May 1680 in a hasty ceremony, as Charles prioritized government work over private matters, even a marriage ceremony.
Charles and Ulrika Eleonora were very different. He enjoyed hunting and riding, while she enjoyed reading and art, and is best remembered for her great charitable activity. She was also limited by ill-health and numerous pregnancies. Charles was very active and busy and while Charles was away inspecting his troops or pursuing his pastimes, she was often lonely and sad. The marriage itself, however, is considered a success, with the King and Queen being very fond of each other. As queen, Ulrika Eleonora had little political involvement and was placed in the shadow of her mother-in-law. During "The Great Reversion" to the crown of counties, baronies and large lordships from the nobility, Ulrika tried to speak on the behalf of the people whose property was confiscated by the crown. But the king told her that the reason he had married her was not because he wanted her political advice. Instead, she helped people whose property had been confiscated by secretly compensating them economically from her own budget. However Charles XI's confidence in her grew over time: in 1690, he named her future Regent, should his son succeed him still a minor. Instead Ulrika Eleonora predeceased him by almost four years. At the time of her death she was personally supporting 17,000 people.
It is said that on his death bed, Charles XI admitted to his mother that he hadn't been happy since Ulrika Eleonora's death.
The marriage produced seven children, of whom only three outlived Charles:
Hedwig Sophia (1681–1708), duchess of Holstein-Gottorp and grandmother of Emperor Peter III of Russia;
Charles XII (1682–1718), who succeeded him to the throne; he had no issue
Gustav (1683–1685)
Ulric (1684–1685)
Frederick (1685–1685)
Charles Gustav (1686–1687)
Ulrika Eleonora ("the younger", 1688–1741), who succeeded her brother on the Swedish throne; no issue
Ulrika Eleonora (the elder) was sickly, and the many child births eventually broke her. When she became seriously ill, in 1693, Charles finally dedicated his time and care to her. Her death in July that year shook him deeply and he never fully recovered. Her infant son Ulric (1684–1685) had been given Ulriksdal Palace, which was renamed for him (Ulric's Dale).