William and Mary ruled together after the so called Glorious Revolution in 1688, that dethroned James II, Mary's father.
After Mary's death, William ruled alone and after this death, having no heirs, the throne passed to Mary's younger sister Anne.
Also Anne left no heirs and that was the end of Stuart dynasty, the throne passed then to Hanover.