Dialogue is the speech between characters. It is when the narrator (you) stops telling the story and the characters speak instead.
Here's some pointers regarding dialogue writing:
Never write dialogue like real-life speech. Why? Because if you listen to real-life speech it is littered with umms and ahhs and errs. Anyone who has ever sat through a meeting or an assembly listening to someone droning on umming and ahhing will know just how frustrating it is. The last thing you want is to inflict that on your reader.
Real life also has moments where you completely forget what you're saying or get side tracked and run off on a tangent or get interrupted. Now all these things can be added to dialogue but in small amounts. We all know someone in life who constantly interrupts us when we talk, they can't wait for your part of the conversation to end so they talk over you. Fine, have a character who does this but DON'T make them a main character because I guarantee your readers would get sick of reading fractured dialogue.
If you want a true version of real-life speech, when you have a conservation with friends, use a dictaphone and tape if for an hour. Then play it back, listen for the errs and ahhs, the long drawn out pauses and the interruptions.
Unless your character is ACTUALLY making a speech, try and avoid them. What do I mean? Long drawn out dialogue where one character just talks and talks, often explaining some poignant moment or situation. Fine, sometimes a plot needs to be re-iterated, maybe a character is telling a new character what has happened to him/her. Keep it brief or just tell bits and use filler for the rest.
Example: Jake stuttered, struggling to put into words the tragedy that had befallen the group. Kate listened intently, nodding or squeezing his hand when he reached moments of painful memories.
"There was no where for us to go?" Jake murmured. "We just had to take it, to ignore everything they did to us. But when they beat Simon, we knew we had to leave." Jake turned red-rimmed eyes towards her, looking at Kate's face for the first time. "He never made it out."
Here we see Jake is telling a tale, we don't need all of it (of course you could lengthen it) though remember the narration should cover some of the tale. Then we throw in some dialogue so we have an idea about what the tale is about and this gets across the emotion Jake is feeling.
If Jake had rattled on for three pages about everything they had been through, it is likely that much of the emotion would have been lost. Dialogue can help, but build a picture slowly with narrations, with description and mood.
IDENTIFY THE SPEAKER
If you have a lot of back and forth dialogue (often happens in arguments) you need to make sure the reader is clear on who is speaking. As a personal preference, I avoid the constant "he said, she said" as I find it clunky. They being said the renowned Terry Pratchett often uses he said she said and it never stops the flow of his work...but then again, his work is awesome so it could just be that his writing it so good, you barely notice the he said she said.
Anyway, I digress... throw in names or motions to explain who is speaking.
"This is all your fault!" Sally snapped, throwing the glass into the fireplace.
Tom shielded his face from the glass fragments. "Why my fault?"
"You always do this, you never think you just rush in!"
Her temper was fraying and Tom felt himself edging unconsciously towards the door. "It's not just me, we both made mistakes."
By adding description and motion (things in the room such as the glass, the fireplace, the door and motion throwing, edging etc) you can build a picture, create a mood and break up dialogue. From this you have a fairly good idea who is speaking. You don't need to identify each line. Especially if there is a constant back and forth.
If there are several people talking, definitely add detail and motion or mention names. Dialogue can be tricky, get friends and family or DA people to read your work ask them to state if there is ambiguity regarding who is speaking.
As your write you will start to find that every character (at least main characters) will have their own voice. They will speak a certain way, sound a certain way maybe even have specific traits when speaking from stutters to shouting to maybe just repeating questions rather than giving answers.
When you write the dialogue make sure you can "hear" their voice. Is the dialogue something they would say? If your have a strong male character, maybe he swears, maybe his voice is rough and he speaks straight. Another character, younger perhaps might mumble, might say five sentences to get out information or a question that could have been asked in 6 words.
Think about your characters' personalities. Do they like to give orders? Do they question everything? Do they struggle to understand or take a long time to explain something? Do they use slang or curse words? Are they in a class that would speak properly (no dropped letters). Are they uneducated where they would mispronounce words or use the wrong word?
Note: If you create a character who uses the wrong words / mispronounces words due to a lack of education or being taught wrong, make sure you mention it somewhere. Or make it clear from some other description so that the reader is aware this is the character's error and not your error.
The jury's out on writing accents. My thoughts, avoid them. If you want to mention your character has a strong accent, fine this will allow the reader to adjust the "voice in their head" to compensate. After all the reader will have already given all your characters voices. If you have an accent, tell the reader early enough.
To write it can be difficult and also insulting. If you ever hear someone mimicking (badly) an accent it can often be some nasty clique. We are all aware of the nasty "leprechaun" accent given to Irish people (as someone who lives with an Irish person, I cringe when people I know try and "do the accent").
People's accents change from area to area. The British accent in many American shows and movies always comes across as quite posh...as if we all wear bowler hats and drink tea with the queen. The most amusing I ever saw was in Independence Day, where it flashed to British Soldiers. I don't even think the Royal Princes (who have served in the armed forces) have that level of poshness to their accent. It gave a very warped view of the British Forces
Anyway, state the accent and just move on let the reader do the rest. I've read books where the words have been butchered in order to "force" an accent. Not only can it be insulting, but the reader can get sick of trying to work out what you've written.
As mentioned though, this is my personal thoughts on the matter.
I have mentioned this before in other tutorials, so just a quick reminder, make sure you use the right words for the right characters and the right settings. Don't use curse words or slang in a medieval fantasy (unless it's curse words that sound right... "like devil blast you, you bastard").
"Fuck You" doesn't really work in a medieval fantasy, but calling someone a bastard, after all that's a correct term is more acceptable.
SAYING WHAT'S NEEDED
Dialogue is important and needs to move the story along. So add it when it's needed, have characters interact or even talk to themselves, the trees whatever you want. But make sure it's relevant.
Having a page of dialogue between two characters over what they want to order at the local tavern is boring, unless it somehow moves the story on or contributes to the development of a character(s)
Remember to add emotion. If a character is sad, happy, angry, scared, lonely, apathetic etc this should come across with descriptions and actions, however dialogue can help.
"How many more?" she asked. The man merely shrugged, remained straight backed barely looking at her. "Tell me!" Lia screamed. "Tell me how many more will die today!"
By breaking up the dialogue you can create a mood. The first question here seems innocent enough. The man's reaction creates a feeling. Suddenly the character Lia demands, screaming then asks another question. Two lines, three pieces of dialogue and a small amount of description can give an image.
So what did you think when you read that example? What image was conjured up? Did you hear her scream? Did you hear the panic or the fear or the anger in her voice? Without more you cannot be sure what she was feeling, but there is emotion there and as a writer I could take it in a number of ways.
It is a good idea to read any dialogue out loud once it's written. My way is to write a few pages and then read through, reading the dialogue out. You find your voice changes, not to match the characters exactly, but their tone, their temperament can come through when you read. This will also help you to hear if there are any clunky dialogue parts. If you're not sure, think about re-writing it, saying it differently try a few ways until the dialogue feels better, flows more smoothly.