First, you need to get the bus to Algeciras, which takes about two hours - see
here.
Then, catch a ferry from Algeciras to Tangier, which takes 1h to 1h30, depending on the ferry you choose - see
here for options.
Then, catch the train from Tangier to Marrakech, either changing in Casablanca or overnight - see
here. Journey time is about 9h.
Pricing information will be on all of those sites. In Algeciras, it's a 10 minute walk from the station to the ferry terminal. In Tangier, you'll arrive at Med Port, quite some distance from the city. This is, however, linked to Tangier's main station by rail.