In 781, Charlemagne made his 3-year-old son Louis the Pious (778 – 840) king of Aquitaine, who was sent there with regents and a court in order to secure the southern border of his kingdom against the Arabs and Moors and to expand southwards into Muslim territory.
This trend resulted in the counts becoming de facto independent of the Carolingian crown under Borrell II in 987, starting since, to call themselves and to be known as dei gratia comes (counts by the grace of god) and dux catalanensis (Catalan dukes) or even Hispaniae subjogator (attorney of Hispania) and Propugnator et murus christiani populi (wall and defender of the Christian folk).
Besalú was made a separate county in 878 for Radulf on the condition that it pass to the heirs of Wilfred the Hairy on his death.
At that time, the power of the Carolingian Empire was waning and the neglected Hispanic March counties were practically independent of its royal authority.
In the early 11th century, Berenguer Ramon I, Count of Barcelona, was able to submit to Sancho III of Navarre as his suzerain, even though he was still legally a vassal of Robert II of France.
With the accession of Robert's father, Hugh Capet, the first non-Carolingian king, in 987, most of the counts refused to pay homage to the new dynasty.
By the Compromise of Caspe of 1412 the County of Barcelona and the rest of the dominions of the Crown of Aragon passed to a branch of the House of Trastamara.
By 1812, once he had full military control over the Principality of Catalonia, he separated it from the Crown of Spain and annexed it to the French Empire.
During the 2nd Spanish Republic and Francoist Dictatorship the Bourbons remained in exile and retained their dynastic titles, including 'Count of Barcelona'.
Although on 26 July 1947, Spain was declared a kingdom, no monarch was designated until 1969, when Franco established Juan Carlos of Bourbon as his official heir-apparent.