NMDA receptors, which regulate synaptic strength and are implicated in learning and memory, consist of several subtypes with distinct subunit compositions and functional properties. To enable spatiotemporally defined, rapid and reproducible manipulation of function of specific subtypes, we engineered a set of photoswitchable GluN subunits ('LiGluNs'). Photo-agonism of GluN2A or GluN2B elicits an excitatory drive to hippocampal neurons that can be shaped in time to mimic synaptic activation. Photo-agonism of GluN2A at single dendritic spines evokes spine-specific calcium elevation and expansion, the morphological correlate of LTP. Photo-antagonism of GluN2A alone, or in combination with photo-antagonism of GluN1a, reversibly blocks excitatory synaptic currents, prevents the induction of long-term potentiation and prevents spine expansion. In addition, photo-antagonism in vivo disrupts synaptic pruning of developing retino-tectal projections in larval zebrafish. By providing precise and rapidly reversible optical control of NMDA receptor subtypes, LiGluNs should help unravel the contribution of specific NMDA receptors to synaptic transmission, integration and plasticity.