The emerging field of optogenetics allows for optical activation or inhibition of neurons and other tissue in the nervous system. In 2005 optogenetic proteins were expressed in the nematode C. elegans for the first time. Since then, C. elegans has served as a powerful platform upon which to conduct optogenetic investigations of synaptic function, circuit dynamics and the neuronal basis of behavior. The C. elegans nervous system, consisting of 302 neurons, whose connectivity and morphology has been mapped completely, drives a rich repertoire of behaviors that are quantifiable by video microscopy. This model organisms compact nervous system, quantifiable behavior, genetic tractability and optical accessibility make it especially amenable to optogenetic interrogation. Channelrhodopsin-2 (ChR2), halorhodopsin (NpHR/Halo) and other common optogenetic proteins have all been expressed in C. elegans. Moreover recent advances leveraging molecular genetics and patterned light illumination have now made it possible to target photoactivation and inhibition to single cells and to do so in worms as they behave freely. Here we describe techniques and methods for optogenetic manipulation in C. elegans. We review recent work using optogenetics and C. elegans for neuroscience investigations at the level of synapses, circuits and behavior.