Genesis 38:8-10 (WEB)
8 Judah said to Onan, “Go in to your brother’s wife, and perform the duty of a husband’s brother to her, and raise up offspring for your brother.”
9 Onan knew that the offspring wouldn’t be his; and when he went in to his brother’s wife, he spilled his semen on the ground, lest he should give offspring to his brother.
10 The thing which he did was evil in the LORD’s sight, and he killed him also.
About Genesis 38: This chapter sits between Joseph’s story and the later history of Jacob’s family. It moves the focus from Joseph to his brother Judah. The setting is Canaan, where Judah leaves his brothers and marries a local woman. He has three sons. Two die because they are wicked in God’s eyes. Judah keeps his daughter-in-law Tamar as a widow, waiting for his third son Shelah to grow up. But he fears losing Shelah too, so he does not give her to him as the law requires. This is a failure of duty and faith. Read the study notes
3 verses · Compare in parallel · Read all of Genesis 38