Judah separates from his brothers, goes to Adullam and marries the daughter of a Canaanite named Shua. They have three sons: Er, Onan and Shelah. Judah chooses a wife named Tamar for Er. Er is wicked in the sight of the Lord, and the Lord puts him to death. Judah tells Onan to fulfill the duty of a brother-in-law to Tamar and give offspring to Er, but Onan knows the child will not be his, and avoids giving her offspring. This displeases the Lord, who also puts him to death.
Judah tells Tamar to remain in her father's house until his son Shelah grows up, but he fears that he too will die and does not follow through. Time passes, Judah's wife dies, and when the mourning is over he goes up to shear his sheep at Timnah. Tamar, seeing that Shelah has grown up and she has not been given to him, takes off her widow's clothes, covers herself with a veil and sits by the road. Judah takes her for a prostitute and sleeps with her. She asks for his signet, cord and staff as a pledge. Judah sends his friend with a young goat to redeem the pledge, but he cannot find her.
Three months later Judah is told that Tamar is pregnant, and he orders that she be burned. She sends him the objects with the message that the owner of these things is the father. Judah acknowledges that she is more righteous than he, because he did not give her his son Shelah. Tamar gives birth to twins. During the delivery one puts out a hand but pulls it back, and the other is born first: Perez, and then Zerah.