After 350 years of The House of Stewarts the English Parliament (without consulting the Scots) passed the Act of Settlement in 1701. This confirmed Queen Anne as heir to the throne after King William.
And if neither of them had legitimate offspring, after Anne, the throne would then go to the Protestant Sophia, Electress of Hanover, who was a grand-daughter of James VI/I and whose mother had been sister to Charles II and James VII/II. The specific aim of the Act of Settlement was to exclude from the succession any Catholic descendants of James VII/II, especially his son, James Francis Edward Stuart.
In due course William and then Anne died without legitimate issue. Shortly before Anne's death in 1714, Protestant Sophia, Electress of Hanover, had also died. The effect of the Act of Succession was to pass the thrones of Great Britain (as since the Act of Settlement, there had been an Act of Union between England and Scotland) and Ireland to George I, who proved a deeply unpopular German-speaking king. George I was challenged by the 1715 and 1719 attempts to replace the House of Hanover with the Jacobites, but remained in power. His son, George II in turn survived the 1745 Jacobite uprising.
After George II the crown skipped a generation, going to George II's grandson, George III. He was at the helm when Britain lost the American War of Independence and suffered a range of problems at home: though he also presided over the Act of Union with Ireland and as a result became the first King of the United Kingdom. George III's later years were blighted by mental illness, and power passed to the Prince Regent, George, Prince of Wales, who later became George IV. He died without legitimate heirs and was succeeded by his younger brother William IV, who also died without legitimate heirs (though with a large number of illegitimate ones) and left the crown to Queen Victoria, his niece and George III's grand-daughter.
Victoria ruled for longer than any other British monarch. She was succeeded by King Edward VII who, taking his dynastic title from his father, Prince Albert's side of the family, became the first monarch of the House of Saxe-Coburg and Gotha.