This is the rule.
For more information, you can read this article from Grammarly.
Summary
In English, titles follow specific capitalization rules known as “title case.” In title case, the first and last words, as well as all major words, are capitalized. Major words typically include nouns, pronouns, verbs, adjectives, and adverbs, while articles, conjunctions, and prepositions are generally not capitalized unless they appear at the beginning or end of the title. Keep in mind that different style guides may have slightly different rules for title capitalization.
A Very Useful Tool
Some examples
Articles
Incorrect: Ernest Hemingway wrote For Whom The Bell Tolls.
Correct: Ernest Hemingway wrote For Whom the Bell Tolls.
Incorrect: Girl on A Train is a thriller by A. J. Waines.
Correct: Girl on a Train is a thriller by A. J. Waines.
Incorrect: Jennifer Egan wrote A Visit from The Goon Squad.
Correct: Jennifer Egan wrote A Visit from the Goon Squad.
Conjunctions
Incorrect: She titled her thesis “Urban Legends: Fact Or Fiction?”
Correct: She titled her thesis “Urban Legends: Fact or Fiction?”
Incorrect: Shakespeare wrote Romeo And Juliet.
Correct: Shakespeare wrote Romeo and Juliet.
Nouns
Style guides agree that nouns should always be capitalized.
Incorrect: The lion, the witch and the wardrobe is by C. S. Lewis.
Correct: The Lion, the Witch and the Wardrobe is by C. S. Lewis.
Verbs
Incorrect: Things fall Apart is by Chinua Achebe.
Correct: Things Fall Apart is by Chinua Achebe.
Adjectives
Adjectives are always capitalized.
Incorrect: Roald Dahl wrote Charlie and the chocolate Factory.
Correct: Roald Dahl wrote Charlie and the Chocolate Factory.
Adverbs
Adverbs are also always capitalized.
Incorrect: Brené Brown wrote Daring greatly: How the Courage to Be Vulnerable Transforms the Way We Live, Love, Parent, and Lead.
Correct: Brené Brown wrote Daring Greatly: How the Courage to Be Vulnerable Transforms the Way We Live, Love, Parent, and Lead.
Prepositions
Norman Maclean wrote A River Runs through It.
But if you were following AP style, you would write it this way:
Norman Maclean wrote A River Runs Through It.