Tamar was the daughter-in-law of Judah. Tamar was first married to Er, Judah's eldest son. Her husband, however, died soon after the marriage. As per custom, it was a brother's duty to produce offspring for a woman if she was widowed before giving her children, and so Judah commanded Onan to fulfill his obligations. Onan, however, had other ideas.
Then Judah said to Onan, "Lie with your brother's wife and fulfill your duty to her as a brother-in-law to produce offspring for your brother." But Onan knew that the offspring would not be his; so whenever he lay with his brother's wife, he spilled his semen on the ground to keep from producing offspring for his brother. (Genesis 38:8-9)
For this behavior (from which comes the word Onanism), the Lord put Onan to death. Judah was now compelled to marry Tamar to his youngest son, Shelah. Afraid, however, that Shelah too would suffer his brothers' fate, Judah sent Tamar back to her father's house, ostensibly to wait for Shelah to come of age.
After enough time had passed by, Tamar realized that Judah didn't intend sending for her and determined to avenge herself. One day, she learned that Judah was on his way to Timnah. Disguising herself as a prostitute, she waited for him on the road to Timnah.
When Judah saw her, he thought she was a prostitute, for she had covered her face. Not realizing that she was his daughter-in-law, he went over to her by the roadside and said, "Come now, let me sleep with you."
"And what will you give me to sleep with you?" she asked.
"I'll send you a young goat from my flock," he said.
"Will you give me something as a pledge until you send it?" she asked.
He said, "What pledge should I give you?"
"Your seal and its cord, and the staff in your hand," she answered. So he gave them to her and slept with her, and she became pregnant by him.
Judah sent a man with a goat to recover his possessions from Tamar, but quite obviously, the girl wasn't to be found. Judah shrugged off his loss.
Three months later, Judah was told that his daughter Tamar was guilty of prostitution and was pregnant. He asked that she be brought out and burned to death. Tamar, however, had a card to play.
As she was being brought out, she sent a message to her father-in-law. "I am pregnant by the man who owns these," she said. And she added, "See if you recognize whose seal and cord and staff these are."
Judah recognized them and said, "She is more righteous than I, since I wouldn't give her to my son Shelah." And he did not sleep with her again.
Tamar gave birth to twins: Perez and Zerah.