Genesis 38:9

9 But Onan was not willing to have a child who would not be his own heir. So whenever he had intercourse with his brother’s wife, he spilled the semen on the ground. This prevented her from having a child who would belong to his brother.

Genesis 38:9 Meaning and Commentary

Genesis 38:9

And Onan knew that the seed should not be his
Should not be called a son of his, but a son of his brother Er; this is to be understood only of the firstborn; all the rest of the children born afterwards were reckoned the children of the real parent of them; this shows this was a custom in use in those times, and well known, and was not a peculiar case: and it came to pass, when he went in unto his brother's wife;
to cohabit with her, as man and wife, he having married her according to his father's direction: that he spilled [it] on the ground, lest he should give his seed to
his brother:
lest his brother's wife he had married should conceive by him, and bear a son that should be called his brother's, and inherit his estate; and this is the sin, which from him is called Onania, a sin condemned by the light of nature, as well as by the word of God, and very prejudicial to mankind, as well as displeasing to God, as follows:

Genesis 38:9 In-Context

7 But Er was a wicked man in the LORD ’s sight, so the LORD took his life.
8 Then Judah said to Er’s brother Onan, “Go and marry Tamar, as our law requires of the brother of a man who has died. You must produce an heir for your brother.”
9 But Onan was not willing to have a child who would not be his own heir. So whenever he had intercourse with his brother’s wife, he spilled the semen on the ground. This prevented her from having a child who would belong to his brother.
10 But the LORD considered it evil for Onan to deny a child to his dead brother. So the LORD took Onan’s life, too.
11 Then Judah said to Tamar, his daughter-in-law, “Go back to your parents’ home and remain a widow until my son Shelah is old enough to marry you.” (But Judah didn’t really intend to do this because he was afraid Shelah would also die, like his two brothers.) So Tamar went back to live in her father’s home.
Holy Bible. New Living Translation copyright© 1996, 2004, 2007, 2013 by Tyndale House Foundation. Used by permission of Tyndale House Publishers Inc., Carol Stream, Illinois 60188. All rights reserved.