Shrugs are a popular exercise to isolate your traps. It will mostly work the upper part of the trapezius muscle, which is the part behind your neck that "pops out". For a complete trap development, you will need to incorporate another exercise that works the lower part of the traps too.
The traps run all the way from the upper part of your neck, to the middle back. Your traps have two functions, pulling the shoulders up, like the shrug. and also pulling the shoulder closer together or farther apart.
Strengthening the traps will improve shoulder mobility, posture, and might help prevent back pain.
The shrug can be done with Barbell, dumbbells, a trap bar and a dedicated machine. The barbell lets you put more weight that possible with dumbbells, but it also requires your shoulders to be in a less natural position, that might cause a bad form during this exercise.
Avoid using too much weight, since it can compress your spine.
Keep your shoulder blades pulled down and back and your chest up, The barbell will cause your shoulders to roll infront a little, try to keep them back as much as you can.
Hold your neck in a natural position. Having your head either too far forward or backwards may cause the neck muscles to perform under the majority of the muscular tension and stimulus; not the traps.
Keep your body and core tight and abs engaged throughout the exercise to protect your spine.
Do not move your hips while shrugging. The movement should be done with your shoulders.
Don't bend your arms, bending the arms will shift the weight to you biceps instead of the traps. keep your arms straight.
Don't roll your shoulders, the barbell should go straight up and down. Rolling the shoulders in unnecessary, and might increase the risk of injury.