Imagine if Harry Potter had ended up with Hermione Granger.

Or if Hermione had found true love with a reformed Draco Malfoy — or Harry had.

Or if Rory Gilmore, of “Gilmore Girls,” had realized, at long last, that she was meant to be with bad boy turned author Jess Mariano.

Or if Elizabeth Bennet and Fitzwilliam Darcy of Jane Austen’s “Pride & Prejudice” met not in Regency-period England, but in this era — while attending Hogwarts School of Witchcraft and Wizardry.

All these scenarios, and countless more, are explored on the Internet, on websites devoted to fan fiction — fanfic, for short.

Fan fiction is what it sounds like — it’s fiction written by fans, who take characters from books, movies, TV shows, cartoons, even real-life bands and the Bible, and either put them in new situations or reimagine the outcomes already penned by their original creators.

Related: A guide to fanfic lingo

“There’s fan fiction for almost everything,” says Kendra Boersen, a Lancaster Public Library circulation assistant who particularly enjoys fanfics based on the TV show, “Supernatural.”

If you’re part of the “Doctor Who” fandom, or the “Percy Jackson” fandom, the “Star Trek” fandom, or even the “My Little Pony” fandom, chances are you’ve read some fanfic about your favorite characters.

“Fan fiction is what literature might look like if it were reinvented from scratch after a nuclear apocalypse by a band of brilliant pop-culture junkies trapped in a sealed bunker,” Lev Grossman, author and journalist, writes in Time magazine.

“The writers write it and put it up online just for the satisfaction. ... The culture talks to them, and they talk back to the culture in its own language.”

As the character Cath says in the novel, “Fangirl,” by Rainbow Rowell: “I'd rather pour myself into a world I love and understand than try to make something up out of nothing.”

Wading through

Kendra Boersen is working on what is known in fanfic circles as a “one shot” — a single-chapter story — on the TV show “Supernatural.”

She reads fan fiction on the websites — the juggernaut of fan fiction sites — and Archive of Our Own.

She says people mostly imagine fanfic fans to be teenagers, but “it’s a whole range of ages,” from 12-year-olds to people with doctoral degrees.

Some fan fiction can be sketchy, so she pays close attention to the ratings systems of the sites she frequents, and to the tags on posts that can signal subjects she’d rather avoid.

“There have been times where I’ve come across summaries or some such, you honestly don’t know — should I call the police?” she says, only half-jokingly.

Plenty of fan fiction is benign, though, she says, noting, “You kind of have to wade through.”

Mary Anne Stanley, youth services manager at Manheim Township Public Library, says it “used to be you had to check under the bed or under the sofa to see what (kids) are reading. Now you have to go into their devices.”

She says some fan fiction isn’t so much shocking as shockingly awful.

“A lot of fiction is really badly written,” Stanley says, “even stuff you see sometimes on The New York Times’ best-seller list.”

But “some of the fan fiction has real promise,” she says.

Composing fan fiction can be a way for fledgling writers to practice their skills.

On some fan fiction sites, prompts are posted, and writers are challenged to take up the prompts.

Donald Himelright, an English teacher at Manheim Township Middle School, says there is “no doubt that fanfic has been a burgeoning writing platform.”

“I think students/teens really feel this style of writing and if it speaks to them, I'll let it do the talking.”

Fan fiction not new

The author Anne Rice told the website Chicagoist that she doesn’t “ever want to read about my characters in someone else’s writing. It’s too upsetting for me, because they are mine and from my mind.”

But J.K. Rowling, whose “Harry Potter” series is perhaps the richest vein being mined by fanfic writers now, has no such qualms.

A spokesman for Rowling’s literary agent told the BBC that the author was “very flattered by the fact there is such great interest in her ‘Harry Potter’ series and that people take the time to write their own stories.”

Rowling’s only caveats: The fanfiction shouldn’t be published for money, and it shouldn’t veer into obscenity.

Joss Whedon, creator of “Buffy the Vampire Slayer” and “Angel,” two TV shows that inspire a lot of fan fiction, also has welcomed fanfic.

“All worthy work is open to interpretations the author did not intend,” Whedon said, in a chat on the website Reddit. “Art isn't your pet — it's your kid. It grows up and talks back to you.”

The erotic best seller “Fifty Shades of Grey,” by E.L. James, began as a “Twilight” fanfiction series titled “Master of the Universe.”

And, as the Wall Street Journal has reported, author Cassandra Clare wrote “Harry Potter” and “The Lord of the Rings” fan fiction before her wildly popular “Mortal Instruments” series of Young Adult fantasy novels was published.

Among Clare’s fanfic offerings: a “Lord of the Rings” parody written in the style of “Bridget Jones’s Diary.”

Stanley, the Manheim Township librarian, says fan fiction isn’t really new — people have been writing parodies of, and homages to, their favorite works forever.

“It’s something that’s always been with us,” Stanley says, “but it’s just exploded because of technology.”

‘Shipping’ characters

Many fanfiction writers like to “ship” their favorite characters — that is, pair them in relationships with other characters. (Slashing is the pairing of same-sex characters.)

So Elsie Hughes, the housekeeper at Downton Abbey, for instance, is shipped with Charles Carson, the upright butler.

And Neville Longbottom, an unlikely but lovable hero in the “Harry Potter” series, is shipped with the ethereal young witch Luna Lovegood, in a pairing known as “Nuna” on Tumblr.

A writer named Anna Todd shipped an original character — an OC, in fanfic parlance — with a boy band member clearly meant to be Harry Styles of One Direction, in her fan fiction series “After” on the website, Wattpad.

Todd signed a “mid-six-figure,” three-book deal with Simon & Schuster’s Gallery Books to publish her series, according to Publishers Weekly.

The film rights also have been sold.

“After” contains lines like this one: “We lay in silence just enjoying the feeling of being so close to each other, within minutes soft snores fall from Harry’s lips.”

Shakespeare — or even Nora Roberts — it isn’t.

But it’s gotten hundreds of millions of reads, and generated a backlash from 1D fans who are angry about Todd’s depiction of their beloved Harry (dubbed Hardin in the books) as a womanizing cad.

For love, not money

Most fanfic writers are writing for the love of their subjects, not for money.

“You’re taking these characters that already exist and putting your own spin on them,” Katie Weaver, 16, and a Hempfield High School junior, says. “You can go wherever you want with it.

A reporter for this newspaper’s Freestyle section, Katie is a fan of the British television shows  “Sherlock,” “Doctor Who” and “Downton Abbey” — all favorite subjects of fanfic writers.

“These shows are so captivating, and there are a lot of things ... they don’t cover, and people want to kind of fill in the blanks,” Katie says. “You’re so inspired by them, you want to write more about them yourself.”

Rachael Rudis, 16, is Katie’s friend and classmate, and another fanfic devotee.

People who write and read fan fiction tend to get deeply involved in reading about, or watching, their favorite characters, notes Rachael (her favorite is Remus Lupin, a wizard and werewolf close to Harry Potter).

“There are people who will say, ‘It’s not really real,’ but these are characters who have affected people so much, they kind of are real in a way,” Rachael says.

And it’s fun to imagine these characters “being in school,” for instance, or “meeting their companions,” Alyssa Richards, 14, and a Manheim Township High School freshman, says.

There is a reason why there were 692,000 fan fiction entries relating to Harry Potter on as of last week.

Rowling’s fans don’t want the “Harry Potter” series to be over, and “are hungry to be connected to those beloved characters,” so they extend the magic by writing their own stories, Mary Anne Stanley says.

As Time magazine noted, Harry Potter is not just the boy who lived — he may be “the boy who lived forever,” thanks in part to fan fiction.

Suzanne Cassidy is a Lancaster Newspapers reporter. She can be reached You can also follow @SuzCassidyLNP on Twitter.