The Hays Code (the informal name for The Motion Picture Production Code), adopted in 1930 but not seriously enforced until 1934, was a set of rules governing American filmmaking that stifled American cinema for over three decades. After a wave of complaints and rulings about the content of movies in the early 20th century, which included the US Supreme Court ruling in Mutual Film Corporation v. Industrial Commission of Ohio in 1917 (which said that film had no First Amendment protection as a form of expression) -- as well as a number of perceived immoral people within the industry itself (most infamously, Fatty Arbuckle) -- the Hays Code was a self-adopted censorship code designed to preempt a government-run censorship program. Will H. Hays created the Code, which placed a number of restrictions on all films to be produced by the Motion Picture Association of America. These were:
- Crime and immorality may never be portrayed in a positive light. If someone performs an immoral act, they must be punished on screen.
- In one especially Egregious example, the novel and the stage play The Bad Seed end with Christine Penmark, mother of the sociopathic Rhoda, giving her dangerous daughter an overdose of sleeping pills and shooting herself—but Rhoda survives, with the implication she will kill again (even more likely now that her mother, the only person aware of her true nature, is out of the picture). In the Hays-Code-compliant film version, Christine survives her suicide attempt, while, in an incredibly contrived and implausible instance of Karmic Death, Rhoda goes to the lake in a thunderstorm to try to find the penmanship medal for which she killed a boy, and a bolt of lightning knocks down a tree bough which falls on her head, killing her. This was apparently lampshaded in the film's unusual "curtain call", in which Nancy Kelly (Christine) takes Patty McCormack (Rhoda) over her knee and spanks her.
- The Hays Office also made the ending of The Big Sleep more violent and decisive than the one originally planned.
- The Reveal in Rebecca also suffered as a result of this. Originally the cruel and faithless Rebecca is murdered by her husband Maxim, but in Alfred Hitchcock's 1940 film version her death is accidental, but is covered up by Maxim because he feels nobody will believe he is innocent of the crime.
- "Correct standards of life" must be presented, unless the plot called for something else. This had the strange repercussion that some directors avoided taking on films that centered on poverty, since it might conflict with the code.
- The law must be respected and upheld.
- All portrayals of nudity and overtly sexual behavior were banned (even between consenting adults). Childbirth and labor could never be shown on screen. You've wondered why, when Melanie Hamilton Wilkes was giving birth, she and Scarlett and Prissy were literally shown only as shadows on a wall? That's why.
- No wonder Rita Hayworth only removed one glove in Gilda.
- The sex symbols of Golden Age Hollywood generally kept their clothes on in their movies for this very reason. It also led to the development of the Sweater Girl trope, because tight sweaters, despite being overt Fan Service, were modest enough to meet the requirements.
- This was what pretty much killed the Betty Boop cartoons.
- Red Hot Riding Hood pushed the limits of what was allowed for fanservice on the silver screen. A lot of the sexually-charged wild takes had to be removed from prints for general audiences, but were reinstated in copies made for American soldiers fighting overseas during World War II.
- Curiously, two Walter Lantz shorts got away with a surprising amount of Fanservice. The shorts in question are "The Greatest Man In Siam" and "Abou Ben Boogie".
- Mocking (and in some cases, to be safe, serious depiction) of religion was verboten.
- This was what almost got the Censored Eleven short "Clean Pastures" banned in the time it was released, because it showed a burlesque of religion with black people shown as angels and going to Heaven (not to mention glorifying gambling and jazz in the same mention as Heaven, both of which were considered taboo back then).
- This led to characters who had been less than exemplary members of the clergy getting new careers in the secular field. Two notable examples are Frollo in the 1939 adaptation of The Hunchback of Notre Dame, who became a judge (predating the Disney version by several decades), and Mr. Collins in the 1940 Pride and Prejudice, who became a librarian.
- Drug use (including alcohol consumption) was banned unless the plot called for it. Under the first code, drug use was only allowed if the story was a cautionary tale against drug abuse or if the druggie gets what he or she deserved for doing it in the first place. Illegal narcotics are strictly prohibited, no matter what the circumstances.
- All detailed (that is, imitable) depiction of crime must be removed, such as lockpicking, safe-cracking, or mixing of chemicals to make explosives.
- Revenge in modern times was not permitted as it might glorify violence (specifically murder). Historical settings might allow it—particularly where there was no law to punish the offender. This means that Westerns were the only movies allowed to have revenge as a theme or premise.
- Topics then considered perverse, such as homosexuality, miscegenation (interracial relationships and marriage), bestiality, or venereal diseases were not to be discussed. The explicitly racist ban on depicting "miscegenation" was used to justify the exclusion of non-white actors from employment, on the principle that the code was breached if either the actors or the characters they were to play were of different "races". A notable example involved passing over Anna May Wong, the leading Chinese-American actress of the time, for the female lead in The Good Earth, because the male lead was white actor Paul Muni. The bestiality ban is also worthy of note, as it (along with its less-than-flattering depiction of marriage, see below) was the reason why Red Hot Riding Hood's original ending  had to be changed before release (though it, much like the "erection takes", exist on a Directors Cut that was sent to overseas soldiers).
- The sanctity of marriage was to be upheld.
- It is widely believed that the Code created the Comedy of Remarriage genre, since it wouldn't count infidelity if the leads were (temporarily) divorced. However, it existed before.
- Using "Oh my God!", "Jesus Christ!", or "Oh, Lord" (and all of its variants) were not allowed (Exception: "God" could be said if used reverently). This led directly to tough, iron-jawed heroes saying "Oh, boy!"
- Profanity of any kind was prohibited. Like the above, this would lead to supposedly tough and gritty protagonists using mixtures of Unusual Euphemism and Gosh Dang It to Heck. This was so bad, the word "damn" was completely disallowed, and any usage of profanity would be likely to result in a hefty fine (which is why Rhett's famous line in Gone with the Wind was considered a big deal back then).
- And finally, the United States flag was to be treated with utmost respect.
These rules could be slightly skirted in film adaptations; for example, they managed to keep the famous line "Frankly my dear, I don't give a damn" in Gone with the Wind because the (mild) swearing was in the original novel. (David O. Selznick was still fined $5000 for it, though.) This was especially true for faithful adaptations of William Shakespeare's plays, which were probably considered too artistically significant to censor; Hamlet, for instance, was filmed over a dozen times despite its main theme of revenge, something normally prohibited by the Office.
It has been suggested that the artificial restraints on plot and characterization imposed by the Hays Code essentially created the American audience's "traditional" demand for black-and-white distinctions between good guys and bad guys and uncomplicated happy endings. By training audiences for generations with stories that were often shoehorned into idiotic simplicity, in essence the Hays Code forced the Viewers are Morons trope into existence.
Since the Code did not apply to the stage, aspiring screenwriters could and did write plays about subjects too sexy or politically controversial for Hollywood. In New York (at least), stage censorship—though not unheard of—was far less of a threat than it had been in the 1920s, and comedies quite freely made fun of the movie censors.
The code was in place until 1968, but its purpose—to prevent government-sanctioned censorship of the film industry—was undercut in 1952 with the "Miracle Decision" (where the US Supreme Court declared that film was protected under the First Amendment as a legitimate artistic medium); in the 1960s, a wave of European (particularly British and Italian films like Alfie and Bicycle Thieves) films that were not subject to the Code started tackling gritty topics to which audiences could relate (and which American studios couldn't touch because of the Code). Since the Hays Code governed production and not distribution, these films were able to be shown in American theaters without the MPAA's prior approval, which put the MPAA at a serious disadvantage.
There were also serious domestic challenges to the Code in the 1960s. The Pawnbroker featured an artistically-essential topless scene and Who's Afraid of Virginia Woolf? featured equally-essential harsh language. Against the considerable critical acclaim of these films and overwhelming public sentiment, the Hays Code tried to bend—with those films being made "special exceptions"—but this "bending" opened the door for every daring filmmaker of the day to petition their own films for similar consideration. Furthermore, this change of criteria encouraged the film company executives to gradually lose their enthusiasm to cooperate with the Code themselves: it was one thing for the Code to object to specific content with an agreed upon criteria, it was quite another those censors to be de facto film critics to arbitrarily determine whether their films were of good enough quality to allow them to be exceptions.
In 1966, MGM outright defied the Code and released the film Blowup (which failed to gain Hays approval due its relatively explicit erotic content). Because the MPAA and the Code could do nothing to stop MGM from distributing the critically-hailed film (which became a smash hit), and because it had been so long since the Code had been put in place (resulting in a difference in public opinion), other studios soon followed MGM's lead; by 1968, almost every studio governed by the MPAA had abandoned the Code. The MPAA soon got the message and finally discarded the Code; in its stead came the MPAA Film Rating System (which, while altered over the years, is still in use to this day) to keep the public happy. The fall of the Hays Code marked the disappearance of the last relic of the Golden Age of Hollywood, and the beginning of the "New Hollywood" era of the late '60s and the '70s.
(It's important to note that the MPAA rating system has been criticized itself by many people—including film critic Roger Ebert, as well as the filmmakers of This Film Is Not Yet Rated—for giving films higher ratings for sex, homosexuality, or other controversial topics (and, to a certain extent, obscenity) than violence. There have also been complaints about the lack of transparency concerning exactly why certain films get the ratings they do; several films have been rated PG with "nothing offensive" as the whole MPAA description, for example.)
Stephen Colbert's book I Am America (And So Can You!) contains a parody "excerpt" from the Code, including rules such as "Characters may not walk and chew gum at the same time," "If a train is shown entering a tunnel, the tunnel shall not be portrayed as enjoying it," "Characters may not discuss the high suicide rate among dentists in a manner that implies they have it coming" and "For Christ's sake, somebody put a bra on Jean Harlow". The excerpt also deliberately omits rule #666.
Another example of mocking the Hays Code goes all the way back to 1942 in a classic Looney Tunes cartoon directed by Bob Clampett, A Tale of Two Kitties, in which the cats Babitt and Catstello plot to devour the ever-prepared Tweety Bird. At one point, Catstello is on a ladder to Tweety's nest and struggling with his fear of heights, while from the ground, Babitt starts pushing his buttons by yelling, "Give me the Bird! Give me the Bird!"—to which Catstello turns to the audience to say, "If the Hays Office would only let me, I'd give 'im the Bird all right". The really fun thing here is that animated shorts like this showed many different examples of breaking the Code—such as excessive violence (though completely bloodless, of course), and (what was then) harsh language—simply because they were animated in ways that took everything to a level of pure parody; rules were subverted, but in as overt as way as possible. (A non-animation example of this sort of Hays Code subversion would be The Three Stooges shorts.)
The full text of the code can be found here. The Broadway musical A Day in Hollywood/A Night In The Ukraine takes the text of Production Code and has the cast dance to it.