"After the United Kingdom leaves the union, no agreement between the EU and the United Kingdom may apply to the territory of Gibraltar without the agreement between the Kingdom of Spain and the United Kingdom," the guidelines released by EU president Donald Tusk say.
The tiny British overseas territory on Spain's southern tip has long been the subject of an acrimonious sovereignty row between London and Madrid, which wants Gibraltar back after it was ceded to Britain in 1713.
But residents overwhelmingly voted to remain with Britain in two sovereignty referendums in 1967 and 2002.
The leaders of the remaining 27 EU countries -- including Spain but excluding Britain -- are set to adopt the guidelines at a summit on April 29.
British Prime Minister Theresa May formally triggered the two-year Brexit process on Wednesday.