There are many options for mounting a decorative shelf to a wall. Among these are direct mounts (using self-contained shelves that come with mounting hardware) and the use of decorative wall brackets to support a shelf that is just a piece of wood, melamine, glass, etc.
NOTE: The methods below require drilling holes in the wall, so may not be suitable for weak walls or for those who rent.
For shelves meant to hold heavier objects, or for nubbly walls, attach the shelf with screws. Most modern self-contained wall mounted shelf units come with a slotted metal plate on the back and some screws and anchors.
Step 1 - Gather your Supplies
Bring together all your supplies, including a step ladder if needed so you can complete the task without running back and forth to the toolbox.
Step 2 - Install the Screws
If one of your screws is going into a wood stud inside the wall, it won't need an anchor. Mark where the screws will go (accuracy is important!), put a piece of tape on the wall to protect it, and pre-drill using the smaller drill bit. Screw the screw into the wall so it protrudes about the thickness of the metal plate. If there is no stud, use an anchor. Mark and tape as before, then drill a hole with the recommended drill bit. Insert the anchor and gently tap with the hammer until it's in (you may just be able to push it in with your thumb). Insert the screw into the anchor and screw it into the thickness of the metal plate. Remove the tape.
Step 3 - Mount the Shelf
Line the larger end of the slots up with the screw heads and slide the slot over the screw. Let the shelf slide downwards until the smaller end of the slots rest on the screws. If the shelf is at all wobbly, remove the shelf and screw the screws in a little further. The shelf should rest firmly on the wall without wobbling.
The technique for mounting decorative shelf brackets is largely the same as for mounting a self-contained shelf, but the measurements you'll be taking will be a little different.
Brackets with mounting plates (such as wooden ones) may have similar mounting hardware to the self-contained shelves, but there are some differences.
Figure out where the brackets need to go. Start with the desired placement of the shelf and work down. Measure the thickness of the shelf. Then measure the distance from the top edge of the bracket to just a fraction beyond where the slot on the metal plate starts; these two numbers added together is how far down from the desired shelf height you need to drill the holes.
Mark the wall. If the brackets have just one metal plate apiece, use the level and mark the wall. If there are two plates, measure from the narrow end of one plate to the narrow end of the other, and make another mark there, making sure they are plumb.
Install the screws—See above.
Mount the brackets—See above. Brackets should not wobble.
Place the shelf on top of the brackets.
Brackets that mount directly to the wall require a similar technique.
Measure as above, except the second measurement will be from the top of the bracket to the screw hole in it. Install anchors as above. Predrill if installing over a stud. To install brackets, line up screw holes with anchors or predrilled holes. Insert screw and screw in until tight. Brackets should not wobble. Place the shelf on top of the bracket.
NOTE: Whichever method you use, it is wise to test the strength of the shelf for a few days using an object that's unbreakable and not of great value. This could save an heirloom from ruin if the shelf fails.