The first step toward learning how to write dialogue is to know how it should be formatted. Center the name of the character who will be speaking the dialogue in all capital letters on the page. The character's dialogue then goes underneath it with normal capitalization about 2.5 inches from the left margin of the page. There is no line space between the character's name and his dialogue. Always put a line space between the dialogue of one character and the name of the next character to speak.
Use parentheticals to indicate an emotion or action before the character's dialogue if the scene calls for it. For example, if a character just ran to catch up to another character, put "(gasping for breath)" right before his dialogue to indicate he is panting. Use "(con't)" as a parenthetical if a character continues talking while other action is happening on-screen.
Expository dialogue is dialogue used to explain something from a scene. For example, a character might say something along the lines of, "It sure has been depressing around here since my wife left." Other types of dialogue are meant to convey a person's personality. A mean person might be constantly making threats or insulting other characters, for example. The dialogue choices for each character should always match his or her personality.
Good dialogue should include a representation of the dialect each character uses. Not everybody speaks the same way, so it is important to represent this fact with a variety of different accents. Write out accents phonetically when scripting the dialogue but do not make it so jumbled that it is difficult to read. Use phonetic spellings with moderation so that those reading the screenplay can understand the dialogue while still getting that the character is using a different dialect.