He was educated at Selkirk Grammar School, Loretto School, and the Edinburgh Academy, as well as the University of St Andrews and 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. He soon made a reputation as one of the most able and versatile writers of the day as a journalist, poet, critic, and historian. He was a member of the Order of the White Rose, a Neo-Jacobite society which attracted many writers and artists in the 1890s and 1900s. In 1906, he was elected FBA.