Liu Bian was born in 176 to Liu Hong (Emperor Ling) and one of his consorts, Lady He. At the time of his birth, he was Emperor Ling's only son because the emperor's other sons who were born before Liu Bian died prematurely. As Emperor Ling believed that he lost his previous sons due to bad luck, he ordered Shi Zimiao (史子眇), a Taoist, to raise his newborn son; Liu Bian was given the title "Marquis Shi" (史侯). Liu Bian's mother, Lady He, became empress in 180. In 181, another of Emperor Ling's consorts, Beautiful Lady Wang (王美人), gave birth to a son, Liu Xie. Empress He, in her jealousy, had Beautiful Lady Wang poisoned to death. The motherless Liu Xie was raised by his grandmother, Empress Dowager Dong, and given the title "Marquis Dong" (董侯).
When his subjects asked him to name one of his sons as crown prince, Emperor Ling had a dilemma between Liu Bian and Liu Xie, his only two surviving sons. He felt that Liu Bian was unfit to be emperor because he was frivolous and unable to command respect, so he preferred Liu Xie. However, he was also worried that if he chose Liu Xie, Empress He would turn to her half-brother, He Jin, for help. He Jin held the position of General-in-Chief (大將軍) and was a highly influential figure in the imperial court. He ultimately did not name either of his sons as crown prince.