The Counts of Celje (Slovene: Celjski grofje) or the Counts of Cilli (German: Grafen von Cilli; Hungarian: cillei grófok) were the most influential late medieval noble dynasty on the territory of present-day Slovenia. Risen as vassals of the Habsburg dukes of Styria, they ruled the County of Cilli as immediate counts (Reichsgrafen) from 1341 and rose to Princes of the Holy Roman Empire in 1436. However, the line became extinct when the last count Ulrich II of Celje was killed in 1456.
The Lords of Sanneck (Žovnek) Castle on the Sann (Savinja) river in Lower Styria were first mentioned around 1123/30. Their ancestors may have been relatives of Saint Hemma of Gurk (d. 1045), who held large estates in the area. The fortress was allegedly already built under the rule of Charlemagne as a stronghold against the Avars.
One Leopold of Sanneck appeared as a supporter of the Habsburg king Rudolf I of Germany in the 1278 Battle on the Marchfeld. In the early 14th century, the Lords of Sanneck allied with the Austrian Habsburgs in their conflict against Duke Henry VI of Carinthia around the Kingdom of Bohemia, making them Habsburg vassals in 1308. Leopold's brother Frederick by marriage inherited the large possessions of the late Counts of Heunburg in 1322; the Celje estates itself became a property of the dynasty in 1333, not before years of feud against Count Ulrich V of Pfannberg and several other rivalling noble dynasties. Frederick finally prevailed with the support of Otto the Merry, the Habsburg duke of Styria. He became governor of Carniola and the Windic March in 1332 and was elevated to comital status by Emperor Louis IV in 1341 at Munich, receiving the title Cylie or Cilli derived from Celje Castle.