Yes, any foreigner can buy a property in Spain without any restrictions, regardless of their nationality or country of residence. Spain imposes no limitations on the acquisition of real estate by foreign nationals, whether from the European Union or third countries.
The only prerequisite is obtaining a NIE (Número de Identificación de Extranjero) — the tax identification number required to sign the purchase deed before a notary, pay taxes, and carry out any financial transaction in Spain. The NIE can be requested at the Spanish consulate in your country of residence, or, if you are already in Spain, at a Police Station with a foreigners' unit.
At Notaría Online we manage the entire purchase process completely online, so you do not need to travel to Spain.