Dendritic spines are small protrusions along dendrites where the postsynaptic components of most excitatory synapses reside in the mature brain. Morphological changes in these actin-rich structures are associated with learning and memory formation. Despite the pivotal role of the actin cytoskeleton in spine morphogenesis, little is known about the mechanisms regulating actin filament polymerization and depolymerization in dendritic spines. We show that the filopodia-like precursors of dendritic spines elongate through actin polymerization at both the filopodia tip and root. The small GTPase Rif and its effector mDia2 formin play a central role in regulating actin dynamics during filopodia elongation. Actin filament nucleation through the Arp2/3 complex subsequently promotes spine head expansion, and ADF/cofilin-induced actin filament disassembly is required to maintain proper spine length and morphology. Finally, we show that perturbation of these key steps in actin dynamics results in altered synaptic transmission.