Genesis 38:2-10
38:2 There Judah saw the daughter of a Canaanite man named Shua. Judah acquired her as a wife and had marital relations with her.
38:3 She became pregnant and had a son. Judah named him Er.
38:4 She became pregnant again and had another son, whom she named Onan.
38:5 Then she had yet another son, whom she named Shelah. She gave birth to him in Kezib.
38:6 Judah acquired a wife for Er his firstborn; her name was Tamar.
38:7 But Er, Judah’s firstborn, was evil in the Lord’s sight, so the Lord killed him.
38:8 Then Judah said to Onan, “Have sexual relations with your brother’s wife and fulfill the duty of a brother-in-law to her so that you may raise up a descendant for your brother.”
38:9 But Onan knew that the child would not be considered his. So whenever he had sexual relations with his brother’s wife, he withdrew prematurely so as not to give his brother a descendant.
38:10 What he did was evil in the Lord’s sight, so the Lord killed him too.