Early modern period
In the early modern period, the Holy Roman Empire was a union of territories in Central Europe under a Holy Roman Emperor the first of which was Otto I. The last was Francis II, who abdicated and dissolved the Empire in 1806 during the Napoleonic Wars. Despite its name, for much of its history the Empire did not include Rome within its borders.
Electorate of Bavaria
The Wittelsbach dynasty which ruled the Duchy of Bavaria was the younger branch of the family which also ruled the Electorate of the Palatinate. The head of the elder branch was one of the seven prince-electors of the Holy Roman Empire according to the Golden Bull of 1356, but Bavaria was excluded from the electoral dignity. In 1621, the Elector Palatine Frederick V was put under the imperial ban for his role in the Bohemian Revolt against Emperor Ferdinand II, and the electoral dignity and territory of the Upper Palatinate was conferred upon his loyal cousin, Duke Maximilian I of Bavaria. Although the Peace of Westphalia would create a new electoral title for Frederick V's son, with the exception of a brief period during the War of the Spanish Succession, Maximilian's descendants would continue to hold the original electoral dignity until the extinction of his line in 1777. At that point the two lines were joined in personal union until the end of the Holy Roman Empire. In 1805, after the Peace of Pressburg, the then-elector, Maximilian Joseph, raised himself to the dignity of King of Bavaria, and the Holy Roman Empire was abolished the year after.