When it comes to literature, there are two related but slightly different definitions. To cite the Oxford Dictionary, canon is:
- The works of a particular author or artist that are recognized as genuine.
- The list of works considered to be permanently established as being of the highest quality.
You'll see the word canon used in both contexts. People talk about whether, say, a particular statement about a particular series is canonical, e.g. is this website published by an author canonical? But you'll also see people talking about the "literary canon" or the "musical canon" or the "western canon." Both uses essentially mean the same thing: the word canon is trying to deliminate whether a particular work is worth considering when answering a particular question, whether that question is "who is Hagrid's father" or "what works of music are worth teaching in schools".
The key word in both definitions is recognized. If you read the definition closely, you'll see that it doesn't say who recognizes things as canon or how works are recognized. And there is quite a bit of debate about what counts as canon. For example, take a look at the following debate over on the Science Fiction and Fantasy Stack Exchange website about whether Pottermore--a website published by the author of the Harry Potter series--is a genuine contribution to that author's body of work. Another example: do half completed works by Tolkien, which were then published posthumously by his son, count as canon? Needless to say, there is actually a great deal of subjectivity involved in determining what is canon and what isn't. Ultimately, it comes down to personal choice rather than objective truth.