Croatia had just found their way into the game when the Spanish side quickly built a 2-0 lead thanks to Alvaro Morata in the 29th minute and Fabian Ruiz three minutes later. Dani Carvajal added a third shortly before the break.
Croatia thought they pulled one back in the 80th minute after Bruno Petkovic had a penalty saved by Unai Simon but got the ball into the back of the net via a rebound.
The goal, however, was ruled out because Ivan Perisic, who assisted Petkovic, had encroached into penalty area when the spot-kick was taken.
Spain's Lamine Yamal became the youngest player in European championship history making his Euro debut at 16 years and 338 days.
Switzerland earlier claimed a 3-1 victory over Hungary that could be crucial for progressing from the Euro 2024 group stage.
Michel Aebischer set up the first goal for Kwadwo Duah in the 12th minute and then struck himself at the end of the first half. They were the first international goals for both players.
Hungary pulled one back from Barnabas Varga in the 66th minute in an improved second half but substitute Breel Embolo wrapped up matters for the Swiss in stoppage time.
Switzerland had upset then world champions France to reach the quarter-finals of the last Euros in 2021, and Saturday's success put them level on three points with hosts Germany, who routed Scotland 5-1 in Friday's tournament opener in Group A.