Quick use of the devices is said to increase survival rates by up to 75%.
The defibrillators, costing Â£1,500 each, come with a recorded message to explain how to use them.
Edinburgh's Lord Provost Donald Wilson launched the project and said: "Not only can the machines help passengers in need, they can be taken off the carriage and used at tram stations."
Charity St John Scotland is installing the defibrillators which are being funded by public donations and businesses including the Royal Bank of Scotland, Virgin Money, Montagu Evans, Charlie Miller, GLM, Phillips and Laerdal, and Newtyne Consultancy and Training.
Each year, only around 5% of the 3,500 people in Scotland who undergo attempted resuscitation outside hospital for a heart attack survive to hospital discharge.
Lynn Cleal, fundraiser and chairwoman of St John Scotland, said: "We are delighted to bring together the donor businesses with Edinburgh Trams to install these life-saving defibrillators now giving a lifeline right across the city.
"The St John and the City project is committed to making defibrillators more accessible to members of the public and, as they will now be on every tram, we hope that they will be able to save more lives in Edinburgh."
Edinburgh trams are to be fitted with defibrillators as part of a campaign to save the lives of heart attack victims.