Sunsets and sunrises are among nature’s greatest visual gifts. But when most people try to photograph them, they end up with shots that are much too dark or much too light…and that lack the rich colors and details of sky and landscape that are so thrilling in real life.

Solution: You can get spectacular sunset and sunrise shots with any camera, even a cell phone, if you know how. Here’s what to do…

Pick the right spot. Sunsets and sunrises look best over an interesting or thematic foreground. Look for simple, strong shapes—a lone tree on a hilltop or a sailboat at anchor, for example. Water makes an excellent foreground, particularly a still harbor or lake, because it creates a mirror of the sky and doubles the color intensity of the shot. When traveling, I scout locations in the afternoon so that I know where to get into position well before the sun begins to set (or rise).

Important: Be sure to never look directly at the sun through any lens—it can cause serious eye damage.

Take care with placing the horizon. Putting the horizon low in the frame accentuates the sky, while placing it higher focuses more attention on the foreground. If you’re unsure where to place the horizon, experiment and shoot some variations and choose your best shots after the fact.

Exploit weather. Arriving and departing storms often create the most dramatic skies. Crepuscular rays, or what photographers call “God rays,” are those biblical shafts of light that shoot down from clouds and are common after storms. In cities, high-pollution days often produce especially vivid sunsets because the dense particulate matter in the atmosphere scatters the sun’s rays even more, heightening the vibrant colors.

Set your exposure carefully. A wide range of exposures will provide different and pleasing results with sunsets and sunrises, but you typically will not get a very good shot if you simply point and shoot, letting the camera automatically set the exposure. Reason: The sun’s brightness will make the camera think the overall scene is much brighter than it actually is, and it will make your shot very underexposed—all you’ll see is the sun and darkness around it. Instead, slight underexposure will generally produce the best shot.

What to do: Before framing your shot, point the camera at the sky on either side of the sun—with the sun not in the frame—and then, if you are using a camera (not a cell phone), press the shutter-release button halfway and hold it there to lock both focus and exposure. Then recompose the scene with the sun in the frame and take the shot. If using a cell phone, try switching to the high dynamic range (HDR) mode. In this mode, the camera will automatically create a series of separate exposures that may compensate for the very bright sun.