Huck grows up in St. Petersburg, Missouri. This fictional place is based on Twain's hometown of Hannibal, Missouri. The novel, published in 1884, is set in the past, about forty to fifty years prior, in the period Twain was growing up and before the Civil War.
The setting is important. First, it is on the Mississippi, making it easy for Jim and Huck to attempt to escape their circumstances by taking a raft upriver to the North. Second, it gives Twain a chance to satirize or poke fun at the inverted morality that Huck internalizes from growing up in a Southern town, in which helping a slave escape seems to Huck a greater sin that slavery itself.
Huck feels intense guilt over abetting the loss of the Widow Douglas's "property" because of the way he has been socialized. When he does finally think for himself and acknowledge what experience has shown him, that Jim is fully human and fully worthy of the dignity of freedom, Huck thinks the price of this might be hellfire, but he does it anyway.
The novel thus affirms the extent to which our morality is influenced by where and how we are raised and the importance of rising above that to find a more universal set of moral principles.