An elaborate sculpted altar was commissioned by the Milanese Confraternity of the Immaculate Conception for their oratory in San Francesco in 1480. A new contract was drawn up in 1483 with Leonardo and the de Predis brothers: a central panel was to be painted by Leonardo alone, and there were to be two side panels showing angels singing and playing musical instruments. Two paintings of angels ('An Angel in Green with a Vielle' and 'An Angel in Red with a Lute') by artists influenced by Leonardo, are undoubtedly those for the altarpiece.
'The Virgin of the Rocks' seems not to refer to the mystery of the Immaculate Conception, but depicts the type of subject that Leonardo might have painted in his native Florence where legends concerning the young Saint John the Baptist were popular.
It was twenty five years until a painting of this subject was finally placed in the chapel. In the interim, Leonardo had painted two versions of the composition: the first (in the Louvre) probably sold in the 1490s to a private client after a financial wrangle with the Confraternity; and a replacement, - the painting that now hangs in the National Gallery - that was never finished despite some help from his studio, but was installed in the chapel in 1508.