It is situated in the historic Upper Silesia region, close to the border with Lesser Poland. According to legend, a Silesian fortress on the nearby Grojec mountain was devastated during the Mongol invasion of Poland in 1241, whereafter the inhabitants moved to the present location. Nevertheless, the settlement was first mentioned in a 1206 deed issued by Bishop Fulko of Kraków. It received market rights from the Upper Silesian Dukes of Opole, town privileges were confirmed by Duke Bernard of Niemodlin in 1454.