Chbosky first conceived random ideas, including "a kid standing up in a tunnel," a girl he likes, and parties he goes to. After five years with these elements in mind, he had the idea of writing the novel during a difficult period in his life. He was experiencing a "bad breakup" which led him to ask, "Why good people let themselves get treated so badly?" The author tried to answer the question with the sentence "we accept the love we think we deserve". That meant to be an advice to remark that one is in charge of one's life as he is referring to "not just romance love but also love of self, it's love of your future, it's the love you have for your life."
The story began when Chbosky was in school, evolving from another book on which he was working. In that book he wrote the sentence, "I guess that's just one of the perks of being a wallflower", which led him to realize "that somewhere in that ... was the kid I was really trying to find." Chbosky began writing the novel in the summer of 1996 while he was in college, and within a month and six weeks he completed the story. He rewrote it into two more drafts, concluding the published version in the summer of 1998.
Charlie, "[his] hope in the form of a character", is loosely based on the author and Chbosky included "countless details" in the novel from the time he lived in Pittsburgh. The other characters were "pieces of real people in [his] life"; Chbosky focused on people's struggles and what they are passionate about, attempting to "hone in [on] the essence of each." The characters of Sam and Patrick were an "amalgamate and celebration" of several people Chbosky has met; Sam was based on girls who confided in him, and Patrick was "all the kids I knew who were gay and finding their way to their own identity."