Most fiction is based on "fantasy" although it is not simple as that. There are many different types of fantasy, even those including real characters, but are still fiction and fantasy.
There are cases in which authors take inspiration from real life, real characters o facts, but these books are mainly a made up story that get real only in book.
Fantasy is a genre of speculative fiction set in a fictional universe, often without any locations, events, or people referencing the real world.