Edinburgh is thought to be the first city in the UK to roll out such an extensive network, planned for later this year.
Lothian Buses will install mobile routers on all 713 buses in its fleet and the 27 new trams, which are to be launched in May. The devices are expected to be fitted later this year.
Funding for the £2 million project will be met by the Westminster government as part of the Connected Capital programme.
A separate branch of the same project involves the provision of wi-fi in public spaces such as the Meadows and Princes Street Gardens, powered by devices on street furniture, which is already in development.
Lothian Buses, which is publicly owned by three councils, has until now offered an internet connection only on the Airlink service between Edinburgh airport and the city centre, along with a handful of trial vehicles.
A tender put out to interested suppliers last month states that the connection would have to be strong enough to cater for 80 passengers on each bus and 240 on trams.
It also told contractors that the provision of 4G would be “essential” given the growth in demand for superfast internet.
Graham Birse, director of the Edinburgh Institute at Edinburgh Napier University, said that there were significant benefits from offering a free network.
He told The Scotsman: “This may not sound like much to some but it’s a very significant development, not only in terms of enhancing the visitor experience but also benefiting businesses.
“Cities and destinations that have advanced wi-fi have found visitors tend to explore more, visit more theatres and events, find restaurants and attractions, and indeed spend more during their stay.
“Until fairly recently, internet access on the move was limited to those with the latest smartphones but, as we saw at Christmas, the top purchase was tablet computers and we have to keep up with the expectation that users will be able to log on wherever they go.”
He added: “North American cities such as Vancouver, San Francisco and Seattle have developed wi-fi on public transport and I’m pleased to see we too are opening up our city to discovery, with all the serious benefits that brings.
“The next challenge is to crack the Glasgow to Edinburgh rail route, which would be a big development for business connectivity.”
The Edinburgh Tourism Action Group has previously highlighted research showing that 47 per cent of visitors expect to be able to use smartphones while on holiday, but expensive overseas charges can put them off.
Councillor Lesley Hinds, chair of the new Transport for Edinburgh organisation, which oversees bus and tram integration, said wi-fi was an important part of providing Edinburgh with an up-to-date transport system.
Ian Craig, chief executive at Lothian Buses, said that there has been significant demand for both wi-fi and real-time timetables, such as the popular Lothian Buses app, which also allows passengers to purchase mobile tickets.
He said: “Creating a free wi-fi network on our newly integrated bus and tram fleet is a logical next step.”