After a lot of Anglians had emigrated to the British Islands in the 5th century, the land of the Anglians came in closer contact with the Danish islands - plausibly by immigration/occupation by the Danes. Later also the contacts increased between the Danes and the people on the northern half of the Jutish peninsula.
As Charlemagne extended his realm in the late 8th century, he met a united Danish army which successfully defended Dannewerk (Danevirke in Danish), a fortified defensive barrier across the south of the territory. A border was established at the River Eider in 811. In the 9th century the border was adjusted to the south, and for a while Hamburg was occupied by Danes.
This strength was enabled by three factors:
The Dannewerk was erected immediately south of the road where boats or goods had to be hauled for approximately 5 kilometers between a bay of the Baltic Sea and the rivulet Rheider Au[?] ("Reider Å" in Danish) connected to the North Sea. There, on the narrowest part of southern Jutland, an important transit market (Haithabu, also known as Hedeby), close to the later City of Schleswig) was established, and protected by the fortification of the Dannewerk.
The wealth of southern Jutland, its riches reflected by impressive archeological finds on the site today, and the taxes from the Haithabu market was, of course, enticing. A separate kingdom of Haithabu was established around year 900 by the Viking chieftain Olaf from Svealand. Olaf's son and successor Gnupa was however killed in battle agains the Danish king, and his kingdom vanished.
The southern border was then adjusted back and forth a few times. For instance the German Emperor Otto II did occupy land north of the River Eider in the years 974-983, stimulating German colonialization[?].
Later Haithabu /Hedeby was burned by Swedes, and first under the reign of King Sweyn Forkbeard (Svend Tveskägg) (986-1014) the situation was stabilized, although raids against Haithabu would be repeated. Again in 1066 Haithabu was destroyed by fire.
Knud Lavard (killed 1131) was called Duke of Jutland, and during the rule of his dynasty Southern Jutland functioned as the Duchy which provided for the expences of Royal Princes, which led to longlasting feuds between the Dukes and the Kings of Denmark 1253-1325.
Knud Lavard had inherited also parts of Holstein, and thereby come in conflict with Count Adolf in the German part of Holstein, as they both were very keen on expanding their influence and pacifying the Wagrian tribe (see: Wends). Count Adolf succeeded and established the County of Holstein (1143) with about the borders it has had since then. Holstein was Christianized[?], lots of the Wagrians were killed and the land was inhabited by settlers from Westphalia, Friesland and Holland. Soon the towns of Holstein, as Lübeck and Hamburg, became serious trade competitors on the Baltic Sea. Denmark tried her best to expand her influence to Holstein too, and during 1203-1227 the Count of Holstein acknoledged the King of Denmark as feudal lord.
The wars between the kings of Denmark and the dukes of Schleswig were expensive, and Denmark had to finance them through extensive loans. The Dukes were usually allied with the Counts of Holstein, who happened to be the main creditors of the Danish Crown, too. In 1326, after a war between Denmark and Holstein, the underage Duke of Jutland was made king of Denmark, and his guardian Count Gerhard of Holstein was entfeofed with the Duchy as an inheritable fief.
This was the time when almost all of Denmark came under the supremacy of the Counts of Holstein, who possessed different parts of Denmark as pawns for their credits. King Waldemar VI (Atterdag) started to regain the kingdom part by part. King Waldemar's son Henrik was in 1364 nominally entfeofed with the Duchy, although he never reached to regain more than the northernmost parts as he couldn't raise the necessary founds to repay the loans.
As both Duke Henrik and King Valdemar died (1374 & [[1375}}) the Duchy was the only important part of Denmark which still was controlled by the Counts of Holstein, who now declared the Duchy to be independent of the Danish Crown.
Queen [[Margaret I of Denmark00 managed however in 1386 to reach an agreement with the creditors, who acknowledged the Danish Queen as feudal lord. The Duchy of Slesvig was thereby again a part of the Danish realm[?] - nominally - but it took another 54 years of feuds until the Duchy in practice contributed with troops or taxes.
In 1448 the Duke of Slesvig was influential enough to get his nephew Count Christiern (Christian) elected King of Denmark, and when the Duke had died King Christian was appointed Duke of Slesvig and Count of Holstein in 1460. It followed a period of a hundred years when the Duchy many times was devided between inheritors.
From the end of the 16th century the Duchy was split in only two parts: one held by the King of Denmark, and the other held by the Duke of Slesvig.
During the 30-years' War the relations between the Duke and the King worsened. Finally in 1658, after the Danes had invaded Swedish territories south of Hamburg, the Duke cooperated with the Swedes in their counter-attack which almost eradicated the Danish Kingdom. The peace treaty stipulated that the Duke no longer was a vassal of the Danish Crown.
As Sweden in 1721 had lost its strength, Denmark could again incorporate the Duchy in the Danish realm, and the prior royal and ducal regions of the Duchy were united. The prior Duke remained Duke of Holstein under the German Emperor until 1773 when (almost) all of Holstein was gained by the King of Denmark (in his role as German Duke of Holstein).
German had been the governmental language during the times of more or less independent Dukes, and remained so. Since the Reformation, German had also been dominating in Church and schools, while Danish was the dominating language among the peasantry.
Ultimately, Danish dominance in Schleswig was vulnerable. With its vigorous trading economic activity, the ethnically German area to the south, expanded its geographic domain. Linguistically Low-German immigrants arrived, and previously Danish-speaking families often came to find it convenient to simply change languages. The Low-German language, rather than Danish, became typical of Holstein and the much of the south Schleswig.
After the Napoleonic wars[?] most of Europe experienced a national awakening. Not the least in the German speaking parts of Europe, as for instance in Schleswig and Holstein. 1806-1815 the government of Denmark had claimed Slesvig and Holstein to be parts of Denmark, which wasn't popular among the Germans. The revolutions 1848 all over Europe led in Schleswig and Holstein to a failed separatist rebellion, and Nationalists in Denmark advocated danification of Schleswig (but not Holstein).
Another factor which doomed Danish interests, was that not only was the power of German culture rising, but indeed, powerful German States, ambitious expansionist states, were growing in the south, namely Prussia and Austria. Schleswig-Holstein would, of course and inevitable, become the subject of a territorial dispute involving military encounters among the three states, Denmark, Prussia and Austria.
Denmark found itself nervous as it became suspected that Frederik VII would leave no son, and that upon his death, the Crown Princess would have no actual legal right to Schleswig-Holstein. Ethnic-Danish citizens of Schleswig Holstein the so-called Eider-Danes[?], panicked over the possibility of being separated from their mother country, agitated against the German element, and demanded that Denmark declare Schleswig and Holstein, or at least Schleswig, as an integral part of Denmark. Prussia, the ethnic-German state directly to the south was amused and thrilled by the anti-German machinations, realizing it had found a pretext to defeat Denmark and seize Schleswig-Holstein for itself, 'liberating' Germans from 'tyrannical' Danish rule, engrossing itself with new valuable territory at the same time.
Prussia plotted to whip Germans throughout the German cultural area into a frenzy so that it could carry out the operation against Denmark. Prussia acted, its plans however backfired as the Great Powers, aghast at Prussia's bold move forced Prussia to back down and gave Denmark a strategic advantage.
Prussia was however persistent, and devised a new scheme a few years later. This time it would dupe its major rival Austria, the other major German power, into assisting Prussia get Schleswig-Holstein. The plan Prussia presented Austria with would use the Prussian and Austrian armies to invade and conquer Schleswig-Holstein in order, as they would claim to 'defend the rights' of the regions German-speaking population, and true-claimant after the Danish king's death. In reality, once conquest was achieved, the claimant would be tossed aside, and Prussia would take half of Schleswig-Holstein for itself, while Austria would get the other half, leaving Denmark with nothing.
Austria, as greedy, but not as manipulative as Prussia, ate up Prussia's promises and agreed to do the joint invasion.
Ultimately, the invasion occurred in 1864, after Christian IX of Denmark merged Schleswig and Holstein into Denmark in 1863 after his ascension to the Danish throne that year. The Danes fought with futility to defend the borders of Schleswig, retreat to Denmark proper, and then were pushed out of the entire Jutland peninsula. Defeat had arrived for Denmark. Denmark capitulated and the Prussian and Austria took Schleswig and Holstein respectively. The Prussian military then threw the Austrian military out of the annexed Holstein, annexing Holstein for itself in 1865 following further battle. The international powers saw Austria's defeat as an example of a greedy nation getting what it deserved, and did nothing to try to stop Prussia fulfilling its agenda.
In any case, because of the mix of Danes and Germans who lived there and the various feudal obligations of the players, the problem was considered intractable by many. Lord Palmerston said of the issue that only three people understood the Schleswig-Holstein question: one was dead, the other had gone insane, and the third was himself, but he had forgotten it.