In 1704, Anglo-Dutch forces captured Gibraltar from Spain during the War of the Spanish Succession on behalf of the Habsburg claim to the Spanish throne. The territory was ceded to Great Britain in perpetuity under the Treaty of Utrecht in 1713. During the Napoleonic Wars and World War II it was an important base for the Royal Navy as it controlled the entrance and exit to the Mediterranean Sea, the Strait of Gibraltar, which is only 14.3 km (8.9 mi) wide at this naval choke point. It remains strategically important, with half the world's seaborne trade passing through the strait. Today Gibraltar's economy is based largely on tourism, online gambling, financial services and bunkering.
During the Second World War, most of Gibraltar's civilian population was evacuated, mainly to London, but also to parts of Morocco and Madeira and to Gibraltar Camp in Jamaica. The Rock was strengthened as a fortress. On 18 July 1940, the Vichy French air force attacked Gibraltar in retaliation for the British bombing of the Vichy navy. The naval base and the ships based there played a key role in the provisioning and supply of the island of Malta during its long siege. As well as frequent short runs, known as "Club Runs", towards Malta to fly off aircraft reinforcements (initially Hurricanes, but later, notably from the USN aircraft carrier Wasp, Spitfires), the critical Operation Pedestal convoy was run from Gibraltar in August 1942. This resupplied the island at a critical time in the face of concentrated air attacks from German and Italian forces. Spanish dictator Francisco Franco's reluctance to allow the German Army onto Spanish soil frustrated a German plan to capture the Rock, codenamed Operation Felix.
en.wikipedia.org