Ocado has invested £17 million in "vertical" farms
Ocado, which delivers food bought online from Waitrose, is planning to grow herbs and leafy greens next to its distribution centres.
It has made two investments in indoor farming. One is a joint venture with 80 Acres, a US vertical farm business, and Priva, a Dutch firm that provides climate control technology.
It has also bought a stake in Jones Food in Scunthorpe.
Ocado's chief executive Tim Steiner said he wanted vegetables grown on the farms to be delivered to kitchens within an hour of being picked.
Steiner said they believe that their investments today in vertical farming will allow them to address fundamental consumer concerns on freshness and sustainability, and build on new technologies that will revolutionise the way customers access fresh produce.
Ocado's distribution deal with Waitrose is due to come to an end in September 2020.
The firm will then start delivering to M&S customers as well as supplying its own-label products and big-name branded goods.
Vertical farming involves producing food indoors, with crops grown on a series of stacked levels in a controlled environment.
Produce from the indoor farms, which help save energy and conserve water, are expected to be delivered to M&S customers.
Jones Food, Europe's largest vertical farm, has more than 16,000 feet (5,000 metres) of indoor growing area, lit by 7.45 miles (12km) of LED lights, which means it can produce crops throughout the year.
It could grow more than 400 tons of food each year.
Meiny Prins, the boss of Priva, said the three-way joint venture with Ocado comes as the global population is growing and there is more of a focus on sustainability.
She said they can develop optimal environments in which plants and food crops experience the best way to grow indoors, using leading-edge technology and solutions which result in substantially lower energy and water use, as well as reducing food waste.