@ketan I need to add a slight correction.
Fossil fuels were not compressed in the 19th Century - they are the products of a multi-million year process involving compression under layers of accumulated sediment as it turns to rock. That energy was sunlight that bathed the dinosaurs/megafauna as they frolicked in the swamps.
Their large scale exploitation was given a huge boost in the late 19th Century by the development of the internal combustion engine. Add in the contributions of Rockefeller (Standard Oil - standardizing the supply chain from extraction to customer) and Ford (mass cars) essentially locked us into our dependency.
Around the same time, Edison, Tesla and others were playing with electricity which was seen as the future.
Funnily enough the first Porsche was electric. https://newsroom.porsche.com/en/products/taycan/history-18563.html
However, the problem of storage raised its head - the battery technologies of the time were just not enough. In contrast, you can put hydrocarbons in cans and carry the energy source around.
Today, we have NO excuse to burn carbon based fuels. There are plenty of alternatives and the storage technologies are getting better all the time.