Dendritic spines of hippocampal neurons are receivers of neurotransmission input that occurs during learning and memory.Dendritic spines stabilization and their structural plasticity underlie synaptogenesis and synaptic plasticity. The morphology and motility of dendritic spines and their precursors, dendritic filopodia, depend crucially on the viscoelastic properties of the actin cytoskeleton and its response to myosin II motor contractility. New data on localization of myosin IIB in the dendritic spine and its precursor filopodia allows precise modeling of the forces involved in protruding filopodia, when the actin network as it is contracted by myosin IIB. The periodic growth and shrinking of filopodia is captured by our model and arises from the competition between contractility and polymerization. The actomyosin contractility and actin polymerization mechanisms are sufficient to reproduce the filopodia motility observed in vivo hippocampal neuron dendritic filopodia. Moving-boundary simulations capture motile filopodia actin cytoskeleton dynamics and corresponding myosin concentration fluctuations in filopodia and mature spines. Our results offer new insights into the stabilization of spine morphology and suggest a biomechanical mechanism for the development of mature spine “mushroom” or “stubby” morphologies.