Duke in Bavaria (German: Herzog in Bayern) was a title used among others since 1506, when primogeniture was established, by all members of the House of Wittelsbach, with the exception of the Duke of Bavaria which began to be a unique position. So reads for instance the full title of Karl I, Count Palatine of Zweibrücken-Birkenfeld and patriarch of the House of Palatinate-Birkenfeld: "Count Palatine by Rhine, Duke in Bavaria, Count to Veldenz and Sponheim". The title grew in importance as Wilhelm, Count Palatine of Zweibrücken-Birkenfeld-Gelnhausen began to use it as his primary title. This choice has also had effect for his descendants.
On 16 February 1799, the head of the House of Wittelsbach Charles Theodore of Bavaria died without issue. Wittelsbach had been the ruling house of Bavaria since 1180 with the title of a Duke of Bavaria, and the higher title of an Elector of the Holy Roman Empire since 1623. As after the Landshut War of Succession primogeniture was established, there could only be one Duke of Bavaria anymore, resulting in the actually quite unprecedented decision to create a title of Duke in Bavaria for the rest of the family, which all members of the House took for themselves, even the older Palatine branch – the other major Wittelsbach possession. Reversely, all Wittelbachs were also Counts Palatine by Rhine. After the death of Charles Theodore, who had unified Bavaria with the Palatinate and the other major possessions of Jülich and Berg in his person, two cadet branches were surviving: one headed by Maximilian I Joseph, Count Palatine of Zweibrücken, the other by William, Count Palatine of Gelnhausen, and both Zweibrücken and Gelnhausen were occupied by the French, which might explain why the custom was abandoned to name cadet branches by the title of their cadet possessions no matter how small.