Britain may take legal action against Spain over tighter border controls at its contested overseas territory Gibraltar.

Prime Minister David Cameron's spokesman confirmed the possibility this afternoon, in an escalation of a dispute that has strained relations between the two countries.

Tensions over Gibraltar - a rocky outpost at the mouth of the Mediterranean to which Spain lays claim - flared this month after Spain complained that an artificial reef being built by Gibraltar would block its fishing vessels.

Spain has imposed tougher checks at the frontier, causing long delays for thousands of tourists and local people.

The Spanish government also floated the idea of a new border crossing fee and a ban on planes using its airspace to reach the territory.

Mr Cameron's spokesman said Britain thinks the tighter border controls are "politically motivated and totally disproportionate" and should be stopped.

"The prime minister is disappointed by the failure of the Spanish to remove the additional border checks this weekend and we are now considering what legal action is open to us," the spokesman said.

A Royal Navy warship set sail for Gibraltar as the row escalated, with London Mayor Boris Johnson telling Madrid to take its "hands off our Rock".

A Spanish foreign ministry spokesman this afternoon said Spain would not back down.

"The controls are not a right, they are an obligation," he told Reuters, adding that the Spanish government would not scrap the controls which it saw as being legal and proportionate to prevent money laundering and contraband of tobacco and other products.

Gibraltar has been a source of tension since Spain ceded the territory to Britain in the Treaty of Utrecht 300 years ago.