One of the elements that distinguishes “How I Met Your Mother” from other sitcoms is its surprising and often clever use of music — in part because series creators Carter Bays and Craig Thomas, along with editor Susan Federman, are all musicians. Bays and Thomas co-wrote and perform the series theme, produced by score composer John Swihart.

Swihart — best known for his music for the indie hit “Napoleon Dynamite” — has scored every episode of “HIMYM.” Editor Federman is an ex-violinist whose sense of rhythm and timing is apparent in the show.

“Music is very important to Carter and Craig,” Swihart says. “They enjoy music, and they understand it.” Swihart’s indie-rock-style score (“an easy, emocore type of rock vibe,” he explains) is written and performed entirely in his Laurel Canyon studio, often just the composer on acoustic guitar and upright piano (adding in drums, bass and other instruments as necessary). He creates the average seven or eight minutes of music per episode in a single day each week.

“It’s a pretty emotional show,” says Swihart (who also scores CBS’ “Accidentally on Purpose,” ABC Family’s “Greek” and Fox’s upcoming “Sons of Tucson”). “A lot of times music sets the mood, and, if not, then you’re playing the joke. It depends on the writing: It’s really more about the story, and that’s why there’s more music (than in the average sitcom).”