The son of a handloom weaver, Gray was born at Merkland, by Kirkintilloch, Dunbartonshire. His parents resolved to educate him for the kirk, and through their self-denial and his own exertions as a pupil teacher and private tutor he was able to complete a course of four sessions at the university of Glasgow. He began to write poetry for Glasgow Evening Citizen and began his idyll on the Luggie, the little stream that ran through Merkland. His most intimate companion at this time was Robert Buchanan, the poet; and in May 1860 the two agreed to proceed to London, with the idea of finding literary employment.
Shortly after his arrival in London Gray introduced himself to Monckton Milnes, afterwards Lord Houghton, with whom he had previously corresponded. Lord Houghton tried to persuade him to return to Scotland, but Gray insisted on staying in London. He was unsuccessful in his efforts to place Gray's poem, The Luggie, in Cornhill Magazine, but gave him some light literary work. He also showed him great kindness when a cold which had seized him assumed the serious form of consumption, and sent him to Torquay; but as the disease made rapid progress, an irresistible longing seized Gray to return to Merkland, where he arrived in January 1861, and died on the 3rd of December following, having the day before had the gratification of seeing a printed specimen copy of his poem The Luggie, published eventually by the exertions of Sydney Dobell. He was buried in the Auld Aisle Churchyard, Kirkintilloch, where in 1865 a monument was erected by friends far and near to his memory.
The Luggie, the principal poem of Gray, is a kind of reverie in which the scenes and events of his childhood and his early aspirations are mingled with the music of the stream which he celebrates. The series of sonnets, In the Shadows, was composed during the latter part of his illness. Most of his poems necessarily bear traces of immaturity, and lines may frequently be found in them which are mere echoes from Thomson, Wordsworth or Tennyson, but they possess, nevertheless, distinct individuality, and show a real appreciation of natural beauty.
The Luggie and other Poems, with an introduction by R. Monckton Milnes, and a brief memoir by James Hedderwick, was published in 1862; and a new and enlarged edition of Gray's Poetical Works, edited by Henry Glassford Bell, appeared in 1874. See also David Gray and other Essays, by Robert Buchanan (1868), and the same writer's poem on David Gray, in Idyls and Legends of Inverburn.