There are many forms of contraception, from condoms, to birth control pills, to surgeries that sterilize men and women, to even just the plain old "pull out" trick when a man orgasms. Yet what do all these things stem from? From the desire to only want the pleasure of sex, while disposing the blessing of God to be fruitful and multiply. When God brought the woman to man, they became married, hence why this verse declares Adam and "his wife",
And what had God declared to them?The man said, "This is now bone of my bones and flesh of my flesh; she shall be called 'woman,' for she was taken out of man." That is why a man leaves his father and mother and is united to his wife, and they become one flesh. Adam and his wife were both naked, and they felt no shame. (Genesis 2:23 [NIV])
He blessed them, to be fruitful and to multiply, through their sexual relationship, within their marriage, thus conveying that the very purpose of their marriage was to allow for a sexual relationship that would thus yield them the blessing of offspring. Even in the Psalms we read that children are a blessing,God blessed them and said to them, "Be fruitful and increase in number; fill the earth and subdue it. Rule over the fish in the sea and the birds in the sky and over every living creature that moves on the ground." (Genesis 1:28 [NIV])
Even so, the purpose of marriage is indeed to be able to have sex, and sex does indeed give pleasure, which is why even Paul says,Children are a heritage from the LORD, offspring a reward from him. (Psalms 127:3 [NIV])
Yet every sexual act done with your spouse ought to be done without preventing conception, as it is brushing off a blessing that God has given, and it is also something that is a sin in accordance with the Law of Moses,But if they cannot control themselves, they should marry, for it is better to marry than to burn with passion. (1 Corinthians 7:9 [NIV])
The wickedness of Onan was not that he wouldn't give offspring to his sister-in-law, because although the Law of Moses does state that a brother-in-law is bound by duty to take the wife of a deceased brother, it is not, however, a law that is punishable by death, if the brother-in-law refuses to take the sister-in-law as wife, it is only a duty that he do so, as we see here,And Onan knowing that the seed will not be his -- that it came to pass whenever he entered to his brother's wife, he discharged upon the ground, to not give seed to his brother. And it appeared wicked before God that he did this; and he put to death also this one. (Genesis 38:9-10 [ABP])
So therefore, the putting to death of Onan was not because he did not fulfill his duty to his deceased brother's sister-in-law, as the Law of Moses does not punish to death any brother that refuses to do this duty, but because he spilled his semen on the ground, meaning that he was preventing conception. The prevention of conception, even the mere spilling of sperm on the ground or anywhere that is not inside a man's wife, is wicked before God, and is thus a sin that is punishable by death to God. Therefore, any man that wastes his semen, or does not discharge inside his wife when he orgasms, or also prevents conception in any way, is indeed sinning against God, a sin that is punishable by death.And if brethren should dwell in the same place, and one of them should die, and there might not be seed to him, the wife of the one having died shall not be outside the husband's family not near. The brother of her husband shall enter to her, and he shall take her to himself as wife, and he shall live with her. [6] And it will be, that the male child, who ever she should give birth to, shall be ordained from the name of the one coming to an end, and his name shall not be wiped away from out of Israel. [7] But if the man does not want to take the wife of his brother; then the woman shall ascend unto the gate to the council of elders, and shall say, the brother of my husband does not want to raise up the name of his brother in Israel -- the brother of my husband does not want to. [8] And the council of elders of that city shall call him, and they shall speak to him. And standing, should he say, I am not willing to take her; [9] then the wife of his brother coming forward to him, before the council of elders, then shall untie his sandal, the one from his foot, and shall spit into his face; and responding she shall say, Thus shall they do to the man who shall not build the house of his brother. [10] And his name shall be called in Israel, House of the Untied Sandal. (Deuteronomy 25:5 [ABP])