The following article contains spoilers for the film “Love, Simon.”

When Keiynan Lonsdale was cast as the love interest in Fox’s “Love, Simon,” he was nervous. Not because he was playing a gay character and would have to film an on-screen kiss, but because he didn’t want to let down the fan base of the book on which the film’s based.

“That was going through my mind maybe like the whole of filming, feeling like people are going to be disappointed that it’s me,” the 26-year-old said. “Luckily, I got over that.”

It helped, he said, that “when the fans found out that it was me who was cast as Bram, there was an undeniable amount of support.” Lonsdale said he “felt very welcomed.”

This is the same feeling projected by “Love, Simon” — which pulled in $11.5 million over its debut weekend. The first major studio film of its kind, a gay teen romantic comedy, it follows 17-year-old Simon (played by “Jurassic World” heartthrob Nick Robinson), who has yet to tell his family and friends that he’s gay. His only confidant is an anonymous classmate, known initially as “Blue,” with whom he trades emails and whom he soon realizes he’s in love with. When another classmate discovers the emails, Simon finds himself threatened with being outed to the entire school, something for which he’s not ready.

The coming-of-age tale, adapted from Becky Albertalli’s “Simon vs. the Homo Sapiens Agenda” and directed by Greg Berlanti, welcomes LGBTQ characters into a genre of film made in the spirit of the beloved teen flicks of John Hughes. It boasts an ensemble of young actors, including Alexandra Shipp, Jorge Lendeborg Jr., Logan Miller and “13 Reasons Why” star Katherine Langford. Lonsdale, known for his role as Kid Flash on “The Flash” and “Legends of Tomorrow,” as well as his part in “The Divergent Series: Insurgent,” plays Bram, a black and Jewish athlete at the school. We find out at the end of the film that Bram is Simon’s online crush, Blue. (Get it? Black + Jew = Blue.)

Lonsdale is openly a member of the LGBTQ community, though Berlanti noted that the actor’s sexuality was not factored into the casting decision.

The Times spoke with Lonsdale, who is of Nigerian, Irish and Danish descent from Australia, about “Love, Simon,” being a superhero, overcoming online racism and navigating the industry as a sexually fluid actor.

A lot of people know you from “The Flash.” How was it booking that particular role?

It was awesome. I had done a couple films in America, and so I was starting to get used to the idea that I can take myself seriously as an actor. Then stepping into a show where I knew it was going to be full-time almost felt like it could be a cool training ground. It was overwhelming, and it was exciting. I also was a huge fan of the show. I watched the first season, so I was obsessed with it, so to be cast in it was really cool. It was also the first time I had been exposed to online racism.

What do you mean by that?

The character is originally Caucasian [in the comic books], and so when I got cast — they had changed the character in the most recent comic books and his father and sister are black, but people still didn’t put two and two together. It was interesting. I was upset and hurt, and I couldn’t understand it.

How did you get past it?

I think one thing that helped — and made me sad, but it made me realize it wasn’t personal — was once I got to set, I found out that Candice [Patton], who plays my sister Iris, had also been receiving it, so I was like, “Whoa, this is what people do? People care about that?” Coming from Australia, of course we still have racism, but it’s different. So it was an education. I needed to experience that. There were definitely things that have tested my emotions, and just learning how to not respond to really awful [stuff], and learning to be like, “It doesn’t matter. I’m good, good exactly as I am.”

What were your initial thoughts reading the “Love, Simon” script and the character Bram?

It’s a little surreal that it was just like this perfectly told story that was so relatable and so true to my own journey, and I really felt for the character. I felt for [him and Simon], so I knew that I desperately wanted to be a part of it. But it just felt too good to be true, something that wouldn’t really happen.

I had the chance to visit set while you all were filming in Atlanta last year. I spoke with some of your cast members about the importance of this story. What do you think it means to people?

It means that they can hopefully be reminded and just know for sure that, one, they matter. That they exist, they’re OK as they are and that the tagline of the movie — that everyone deserves a great love story — there’s a lot of truth in that. I think a lot of people don’t really feel very worthy or deserving of love, and that doesn’t even just have to relate to a struggle with sexuality, but just in general. I hope this movie inspires people.

As an out actor, what are your hopes for where this film can kind of push queer storytelling and your career?

I think if there’s an overwhelming amount of support, which I think and hope that there will be, it proves and it dispels that lie that we’ve been told since as long as I can remember that you can’t have a gay leading character, you can’t be a gay or a queer actor in Hollywood and play big roles or sell out theaters. It’s a lie. It’s the same lie that was told about female-driven movies or stories or female directors. It’s like, these are lies based out of fear, and we have an opportunity to just swat those away, kindly.

In terms of my career ... I’m just like, “You know what, I’m good. Whatever happens in my career, whatever happens in my life, I’m good.” I’m going to go with the flow. I’m going to choose projects that make me feel like [“Love, Simon”] does.

And Kid Flash too. It just struck me that you’re a queer black actor playing a superhero, in both the pre- and post-“Black Panther” world.

We were painted a very specific picture about what a queer man is, and no one ever told us that we could be superheroes — and we can.

trevell.anderson

@latimes.com