That is true.
Newton came up with the idea that gravity (which was known to exist on Earth's surface) actually extends to infinity, but grows weaker with distance. This theory explained the motions of the planets with accuracy.
The story of an apple falling on Newton's head is fictional.