Lens was initially a fortification from the Norman invasions. In 1180, it was owned by the Count of Flanders, and sovereignty was exercised by the Crown of France. In the 13th century, Lens received a charter from Louis VIII of France, allowing it to become a city. The Flemish razed the city in 1303. Prior to this, the city's population relied on its markets. In 1526, Lens was made part of the Spanish Netherlands under the ownership of the French monarchy, and only passed back to France on 7 November 1659 with the Treaty of the Pyrenees.