"Mad as a hatter" is a colloquial phrase used in conversation to refer to a crazy person. In 18th and 19th century England mercury was used in the production of felt, which was used in the manufacturing of hats common of the time. People who patronised these hat factories were exposed daily to trace amounts of the metal, which accumulated within their bodies over time, causing some workers to develop dementia caused by mercury poisoning (called mad hatter syndrome). Thus, the phrase became popular as a way to refer to someone who was perceived as insane.
Roger Crab, a 17th-century eccentric who, after working for a short time as a hatter, gave all his goods to the poor and wore homemade sackcloth clothes.
An adaptation of the Anglo-Saxon word atter meaning poison, closely related to the word adder for the poisonous Crossed Viper. Lexicographers William and Mary Morris in Morris Dictionary of Word and Phrase Origins (1977) favour this derivation because "mad as a hatter" was known before hat making was a recognized trade. According to A Dictionary of Common Fallacies (1980), "'mad' meant 'venomous' and 'hatter' is a corruption of 'adder', or viper, so that the phrase 'mad as an atter' originally meant 'as venomous as a viper'."
19th-century hatters in Danbury, Connecticut, developed a condition known colloquially as the Danbury Shakes. The condition was characterized by slurred speech, tremors, stumbling, and, in extreme cases, hallucinations. 
In a section of the January–June 1829 issue of Blackwood's Edinburgh Magazine, headed Noctes Ambrocianæ. No. XL1V, there is a conversation between a group of fictional characters:
NORTH: Many years – I was Sultan of Bello for a long period, until dethroned by an act of the grossest injustice; but I intend to expose the traitorous conspirators to the indignation of an outraged world.
TICKLER (aside to SHEPHERD.): He's raving. SHEPHERD (to TICKLER.): Dementit.
ODOHERTY (to both.): Mad as a hatter. Hand me a segar.
Canadian author Thomas Chandler Haliburton used the phrase twice in his 1835 book The clockmaker; or the sayings and doings of Samuel Slick of Slickville: "And with that he turned right round, and sat down to his map and never said another word, lookin' as mad as a hatter the whole blessed time" and "Father he larfed out like any thing; I thought he would never stop – and sister Sall got right up and walked out of the room, as mad as a hatter. Says she, Sam, I do believe you are a born fool, I vow."
^Mercury Workshop, p. 23, Ohio Indoor Air Quality Coalition, 2008. "In the late 1800’s hat makers, or hatters, used to use mercury nitrate when working with beaver fur to make felt. Over time, the hatters started exhibiting apparent changes in personality and also experienced tremors or shaking. Mercury poisoning attacks the nervous system, causing drooling, hair loss, uncontrollable muscle twitching, a lurching gait, and difficulties in talking and thinking clearly. Stumbling about in a confused state with slurred speech and trembling hands, affected hatters were sometimes mistaken for drunks. The ailment became known as 'The Danbury Shakes' in the community of Danbury where hat making was a major industry. In very severe cases, they experienced hallucinations. The term “mad as a hatter” may be a product of mercury toxicity. The practice did not completely stop until 1943."