Crime fiction is the literary genre that fictionalises crimes, their detection, criminals, and their motives. It is usually distinguished from mainstream fiction and other genres such as historical fiction or science fiction, but the boundaries are indistinct. Crime fiction has multiple subgenres, including detective fiction (such as the whodunit), courtroom drama, hard-boiled fiction and legal thrillers. Suspense and mystery are key elements that are nearly ubiquitous to the genre.
The earliest known crime fiction is Thomas Skinner Sturr's anonymous Richmond, or stories in the life of a Bow Street officer (1827); the earliest full-length short-story in the genre is The Rector of Veilbye by the Danish author Steen Steensen Blicher, published in 1829. Better known are the earlier dark works of Edgar Allan Poe (e.g., "The Murders in the Rue Morgue" (1841), "The Mystery of Marie Roget" (1842), and "The Purloined Letter" (1844)). Wilkie Collins' epistolary novel The Woman in White was published in 1860, while The Moonstone (1868) is often thought to be his masterpiece. French author Émile Gaboriau's Monsieur Lecoq (1868) laid the groundwork for the methodical, scientifically minded detective. The evolution of locked room mysteries was one of the landmarks in the history of crime fiction. The Sherlock Holmes mysteries of Arthur Conan Doyle are said to have been singularly responsible for the huge popularity in this genre. A precursor was Paul Féval, whose series Les Habits Noirs (1862–67) features Scotland Yard detectives and criminal conspiracies. The best-selling crime novel of the nineteenth century was Fergus Hume's The Mystery of a Hansom Cab (1886), set in Melbourne, Australia.