Overview
Onan was a figure detailed in the Book of Genesis chapter 38, as the second son of Judah who married the daughter of Shuah the Canaanite. Onan had an older brother Er and a younger brother, Shelah as well. After being commanded by his father, Judah, to perform his duty as a husband's brother according to the custom of levirate marriage with the late Er's wife Tamar, Onan instead refused to perform his duty as a levirate and "spilled his seed on the ground whenever he went in" because "the offspring would not be his", and was thus put to death by Yahweh. This act is detailed as retribution for being "displeasing in the sight of Lord".
Biblical account
New International Version
8 Then Judah said to Onan, "Go in to your brother's wife and perform the duty of a brother-in-law to her; raise up offspring for your brother."
9 But since Onan knew that the offspring would not be his, he spilled his semen on the ground whenever he went in to his brother's wife, so that he would not give offspring to his brother.
From Wikipedia (CC BY-SA 4.0).