Origins: In the 18th century, mercury salts were used to make felt for fancy hats. The process required copious amounts of the element, a substance then not understood to be as dangerous as we now know it to be.
Hat makers who day after day handled mercury-soaked fabric risked mercury poisoning, a condition that affects the nervous systems. Those so exposed would in time develop uncontrollable twitches and trembles, making them appear demented to the casual observer.
Even though there exists a strong tie between mercury poisoning and strange behavior in those long-ago hatters, it's still more than likely the term we now toss about so casually did
Whatever the definitive origin of mad as a hatter, we know the term wasn't coined by Lewis Carroll in his 1865 Alice's Adventures in Wonderland. The saying turns up in Thackeray's 1849 Pendennis and Thomas Chandler Haliburton's 1837 The Clockmaker.
Carroll's "hatter" might well have been modeled on Theophilus Carter, an eccentric furniture dealer who characteristically sported a top hat. Carter was neither a hat maker nor had been exposed through his work to mercury fumes — if he had indeed been Carroll's inspiration for the "Mad Hatter" of Alice, it would have been because he was a somewhat nutty real-life character much given to the wearing of highly noticeable hats. There also exists a possibility Carroll was unaware of the mercury connection to the existing saying. It's also possible he had not previously encountered the saying and thus thought he had coined it himself.
Carroll's Alice is replete with word play. He loved to twist words, and encoding double and triple meanings into his work was for him part of the fun. His Mad Hatter could therefore be a caricature of Theophilus Carter, a real person of his acquaintance, while his mad as a hatter could have been a twist on the pre-existing saying, mad as a March hare. Those familiar with Alice will recall that the March Hare was the constant companion of the Mad Hatter.
Moreover, mad at that time had more than a few meanings: "off the rocker" and "angry," but also "venomous," which suggests yet another twist in the game. According to A Dictionary of Common Fallacies:
Barbara "mercury rising" Mikkelson
Last updated: 18 May 2010
Beckwith, George [editor]. "Mad as a Hatter." Beckwith's Almanac. Vol. 48, 1895 (p. 89). Edwards, Elizer. Words, Facts, and Phrases. London: Chatto and Windus 1882 (p. 347). Phyfe, William Henry P. 5,000 Facts and Fancies. New York: Putnam, 1901 (p. 362). Rawson, Hugh. Devious Derivations. New York: Crown Trade Paperbacks, 1994. ISBN 0-517-88128-4 (p. 135). Ward, Philip. A Dictionary of Common Fallacies. New York: Oleander Press, 1980. ISBN 0-900891-65-3.