The earliest history of Visby is uncertain, but it is known to have been a centre of merchandise around 900 AD.
It was inhabited as early as the Stone Age, probably because of the access to fresh water and a natural harbour.

In the 12th century, Visby Cathedral, dedicated to Saint Mary, was constructed.
It was reshaped in the 13th century to its current appearance, and was officially opened in 1225, by the bishop of the Swedish city of Linköping (in regional map).
Several other churches were also constructed in the ensuing centuries.
The city flourished, thanks to the German Hanseatic League.

The work on the ring wall was likely begun in the 12th century.
Around 1300, it was rebuilt to reach its current height, acquiring the characteristic towers, although some towers were not constructed until the 15th century.
The ringwall is still largely intact.

In the first half of the fourteenth century (1300-1350) Visby was at the height of its wealth and influence, and it was during this time that Laws of Wisbuy, a set of maritime laws that had broad influence in the Baltic and beyond, were probably promulgated.

In 1361, Gotland was conquered by Valdemar IV of Denmark.
1,800 Gotlanders were killed in battle in front of the city.
Valdemar tore down part of the wall, set up three huge beer barrels and threatened to turn his men loose to pillage the town unless they were filled with silver and gold.
The Visby city fathers fulfilled the demand, with churches stripped of their valuables.
Valdemar added "King of Gotland" to his title list.
His treatment of Visby, a member of the Hanseatic League, precipitated that League into war with Denmark; however, though Valdemar was forced into various concessions, he retained Visby as a Danish city.

In 1391, 1394 and 1398, it was taken and plundered by the Victual Brothers, pirates who sailed the Baltic Sea.
An invading army of Teutonic Knights conquered Gotland in 1398, destroyed Visby and expelled the Victual Brothers.
In 1409, Grand Master Ulrich von Jungingen of the Teutonic Knights guaranteed peace with the Kalmar Union of Scandinavia by selling the island of Gotland to Queen Margaret of Denmark, Norway and Sweden.

In 1411, the Norwegian, Danish and Swedish King Eric of Pomerania had the castle of Visborg constructed, and settled himself there for twelve years, during which the city virtually became a pirates' nest, and the commerce halted.
As of 1470, the Hanseatic League rescinded Visby's status as a Hanseatic town.

In 1525, the final blow came.
In the Danish throne quarrel, the Lübeck, a Free City of the Holy Roman Empire and a leading member of the Hanseatic League, supported Frederick I, while Søren Norby the Danish governor of Gotland fought for Christian II, even after Christian's official resignation in 1523.
While Norby fought a military action in Sweden, the Lübeckers successfully attacked Visby and set the city on fire from four sites.
But unlike widespread belief, several churches survived at first.
The churches of St. James (which already had been closed before), St. Nicholas and St. Gertrude were sacked by Lübeck's army.
With the reformation, all churches except St. John, which became the city parish, were closed.
In 1528, the citizens of Visby sacked the church of the Holy Trinity, or the church of Our Lord (Swedish: Drottens kyrka) in revenge for the plundering of their town.
In 1533–34, the new Danish governor, Henrik Nielsen Rosenkrantz, demolished St. John's and St. Peter's churches to improve the defence of his castle Visborgs slott.
St. Mary's Cathedral remained the last functional church and became the new city parish.

Gotland was again taken into Sweden's possession in 1645, by the Treaty of Brömsebro, after 300 years of Danish rule.
The city developed slowly as things were left as they were.
In the mid 18th century, after a plague had reduced Visby's population, some attempts were made by Swedish government officials to improve living standards, but little was accomplished.
Not until the early 19th century did Visby once again attract commerce and a harbour industry
The earliest history of Visby is uncertain, but it is known to have been a centre of merchandise around 900 AD. It was inhabited as early as the Stone Age, probably because of the access to fresh water and a natural harbour.
In the 12th century, Visby Cathedral, dedicated to Saint Mary, was constructed. It was reshaped in the 13th century to its current appearance, and was officially opened in 1225, by the bishop of the Swedish city of Linköping (in regional map). Several other churches were also constructed in the ensuing centuries. The city flourished, thanks to the German Hanseatic League.
The work on the ring wall was likely begun in the 12th century. Around 1300, it was rebuilt to reach its current height, acquiring the characteristic towers, although some towers were not constructed until the 15th century. The ringwall is still largely intact.
In the first half of the fourteenth century (1300-1350) Visby was at the height of its wealth and influence, and it was during this time that Laws of Wisbuy, a set of maritime laws that had broad influence in the Baltic and beyond, were probably promulgated.
In 1361, Gotland was conquered by Valdemar IV of Denmark. 1,800 Gotlanders were killed in battle in front of the city. Valdemar tore down part of the wall, set up three huge beer barrels and threatened to turn his men loose to pillage the town unless they were filled with silver and gold. The Visby city fathers fulfilled the demand, with churches stripped of their valuables. Valdemar added "King of Gotland" to his title list. His treatment of Visby, a member of the Hanseatic League, precipitated that League into war with Denmark; however, though Valdemar was forced into various concessions, he retained Visby as a Danish city.
In 1391, 1394 and 1398, it was taken and plundered by the Victual Brothers, pirates who sailed the Baltic Sea. An invading army of Teutonic Knights conquered Gotland in 1398, destroyed Visby and expelled the Victual Brothers. In 1409, Grand Master Ulrich von Jungingen of the Teutonic Knights guaranteed peace with the Kalmar Union of Scandinavia by selling the island of Gotland to Queen Margaret of Denmark, Norway and Sweden.
In 1411, the Norwegian, Danish and Swedish King Eric of Pomerania had the castle of Visborg constructed, and settled himself there for twelve years, during which the city virtually became a pirates' nest, and the commerce halted. As of 1470, the Hanseatic League rescinded Visby's status as a Hanseatic town.
In 1525, the final blow came. In the Danish throne quarrel, the Lübeck, a Free City of the Holy Roman Empire and a leading member of the Hanseatic League, supported Frederick I, while Søren Norby the Danish governor of Gotland fought for Christian II, even after Christian's official resignation in 1523. While Norby fought a military action in Sweden, the Lübeckers successfully attacked Visby and set the city on fire from four sites. But unlike widespread belief, several churches survived at first. The churches of St. James (which already had been closed before), St. Nicholas and St. Gertrude were sacked by Lübeck's army. With the reformation, all churches except St. John, which became the city parish, were closed. In 1528, the citizens of Visby sacked the church of the Holy Trinity, or the church of Our Lord (Swedish: Drottens kyrka) in revenge for the plundering of their town. In 1533–34, the new Danish governor, Henrik Nielsen Rosenkrantz, demolished St. John's and St. Peter's churches to improve the defence of his castle Visborgs slott. St. Mary's Cathedral remained the last functional church and became the new city parish. 
Gotland was again taken into Sweden's possession in 1645, by the Treaty of Brömsebro, after 300 years of Danish rule. The city developed slowly as things were left as they were. In the mid 18th century, after a plague had reduced Visby's population, some attempts were made by Swedish government officials to improve living standards, but little was accomplished. Not until the early 19th century did Visby once again attract commerce and a harbour industry
Visby