Background: Moderate-to-severe postoperative pain following craniotomy has a high incidence in pediatric patients. Such pain may cause agitation, intracranial hypertension, epileptic seizures, and postoperative hematoma, which affect morbidity and mortality. Although scalp nerve block (SNB) achieves satisfactory pain relief except for suboccipital mid-craniotomy in adults and ropivacaine is widely used as a long-acting peripheral nerve block agent in children, there are few studies of SNB with ropivacaine in pediatric patients undergoing craniotomy. In addition, the neurosurgery operation time is relatively long, but the duration of action of SNB is limited. It is generally believed that postoperative SNB is better than preoperative SNB for postoperative analgesia. However, considering the concept of preemptive analgesia, we believe that preoperative SNB may achieve a longer postoperative analgesia effect than we expected. Methods: This trial is a single-institution, prospective, randomized, controlled, double-blind study. A total of 180 children aged between 1 and 12 years who are undergoing elective craniotomy will be randomly allocated in a 1:1: 1 ratio to three groups: group B (preoperative ropivacaine block group), group A (postoperative ropivacaine block group), and group N (nonblocking control group). This randomization will be stratified by age in two strata (1-6 years and 7-12 years). The primary outcome is the total consumption of sufentanil within 24 h after surgery. The secondary outcomes include assessment of pain scores, total consumption of sufentanil and emergency-remedy medicine consumption at observation points, the occurrence of postoperative complications, and the length of hospitalization after surgery.