Lang was born in Selkirk. He was the eldest of the eight children born to John Lang, the town clerk of Selkirk, and his wife Jane Plenderleath Sellar, who was the daughter of Patrick Sellar, factor to the first duke of Sutherland. On 17 April 1875 he married Leonora Blanche Alleyne, youngest daughter of C. T. Alleyne of Clifton and Barbados. She was (or should have been) variously credited as author, collaborator, and/or translator of Lang's Color/Rainbow Fairy Books he edited.
He was educated at Selkirk Grammar School, Loretto, and at the Edinburgh Academy, St Andrews University and at Balliol College, Oxford, where he took a first class in the final classical schools in 1868, becoming a fellow and subsequently honorary fellow of Merton College. As a journalist, poet, critic and historian, he soon made a reputation as one of the most able and versatile writers of the day. In 1906 he was elected FBA.
He died of angina pectoris at the Tor-na-Coille Hotel in Banchory, Banchory, survived by his wife. He was buried in the cathedral precincts at St Andrews.