Genesis 38:9

And Onan knew that the seed should not be his; and it came to pass, when he went in unto his brother’s wife, that he spilled it on the ground, lest that he should give seed to his brother.

Onan’s act of spilling his seed on the ground gives its name to a form of sexual wrongdoing called Onanism. That act is a violation of the law of chastity. It stands in the same category as indulging lustful thoughts and as excessive sexual conduct even within marriage. Those who become confirmed practitioners of Onanism become deeply morally depraved. Their depravity does not destroy their accountability. When passion or self-interest urges them to sin, they often give little weight to right and wrong.