Although no one is certain the tale is true, legend has it that Forrest Mars, Sr.―the first M in M&Ms―visited Spain during the Spanish Civil War (1936–1939), where he saw soldiers eating small chocolates with a hard, sugary coating that prevented the candies from melting. In 1940 Mars made his own batch of chocolate candy pellets, inventing the recipe for M&Ms. He brought his idea to the Hershey Corporation, and a partnership was formed. The design was patented on March 3, 1941. That year, M&M®, Ltd. began production in Newark, New Jersey, and the first M&Ms® went on sale.
At first they were sold in cardboard tubes and marketed to the military as a snack that could travel well in different climates. Many soldiers in World War II ate these candies. By the late 1940s, M&Ms were widely available to the public. The popular slogan, “It melts in your mouth, not in your hands” was trademarked in 1954. In 1981, M&Ms went to outer space when space-shuttle astronauts brought M&Ms with them on their flight.