Tangier is a very short ride ferry trip away from Southern Spain, and more specifically, Tarifa, a small coastal town between Gibraltar and the Portuguese border.
In terms of the ferry, I strongly recommend taking the fast ferry which gets you in bit more than an hour directly into the old town of Tangier whereas the slower ferries go to Tangiers-Med, which is outside of Tangier and especially if you’re going to Tangier for a day trip you don’t want to loose time in transits on the Moroccan side. Two ferry companies operate ferries to Tangier from Tarifa, and we used FRS where we could get tickets in advance.
Beyond thinking which ferry to take, when going to Tangier, the first thing to decide is whether you want to go there with a tour group, hire a local guide to take you around old town, or just explore everything on your own. We eventually hired a local guide when we arrived in the harbour, mostly since we wanted him to keep away the people trying to sell us everything while wondering in the old town. I’m not sure if you would really need one but it is easy to get lost in the tiny alleys of the old town and a guide for 4-6h only costs 10USD.
Before hopping on the ferry, we also used an hour exploring Tarifa which proved to be a sympathetic small town where if you have time could either enjoy lunch or dinner.