Genesis 38:9

New International Version - UK Bible (NIVUK)
But Onan knew that the child would not be his; so whenever he slept with his brother’s wife, he spilled his semen on the ground to avoid providing offspring for his brother.

Read Genesis 38:9 in other translations