The Golden Age
Mary Batson was born as the twin sister of Billy Batson, and both of them were cared for by a nanny named Sarah Primm. When the young children were orphaned after their parents died in a tragic car wreck, Primm substituted Mary for the baby girl of another family she also nursed for who had suddenly died, and then sent Billy to an orphanage, separating the twins for their entire early childhoods.
Some ten years after his parents' death, Billy Batson was now an on-air reporter and personality for WHIZ Radio, as well as the Super Hero Captain Marvel. He met his sister Mary Bromfield when she was competing in an on-air contest with several other contestants. Coincidentally, during this contest Billy received an urgent message from Sarah Primm, who was dying and requested to see him right away. On her deathbed, she told Billy about his twin sister, and gave him a locket broken in half. Before she died, she told Billy that his sister wore the other half of the locket.
Remembering that Mary Bromfield also wore a broken locket, he and Captain Marvel Jr. followed Mary's limousine home. But not long after, Mary, who came from a wealthy family, was kidnapped for ransom, and Captain Marvel and Marvel Jr. managed to save Mary. Soon after, Billy Batson discovered that Mary's locket matched his own, and was therefore his long lost sister. Revealing his secret identity to her, Mary wondered if she had access to the power of Shazam, due to being his twin. Billy scoffed at the idea, suggesting the old wizard would never grant such power to a "mere girl." But when Mary said the magic word "Shazam," she transformed into a female version of Captain Marvel, although she retained her teenaged outer appearance.
Mary Marvel had many adventures throughout the Golden Age, both with the rest of the Marvel Family, as well as on her own. After a twenty-year absence, Mary Marvel and the rest of the Marvel Family reemerged, and had several more adventures during the Bronze Age, when she discovered that her Earth was designated Earth-S in the greater DC multiverse.
Post-CRISIS ON INFINITE EARTHS
In the post-CRISIS timeline, Mary Batson's backstory was similar to her Golden Age origin, as she was still Billy Batson's long-lost twin, who was separated from her brother as a young child, and raised by Nick and Nora Bromfield. Reuniting with her brother in her teens, she too discovered she could access the powers of the Rock of Eternity when shouting the magic word Shazam.
While in her Super Hero form, Mary Marvel now resembled an adult, similar to how Billy Batson transformed into an adult hero when he said those same words. In fact, she looked almost identical to her late mother in her super-powered form. To differentiate herself from her brother, she later wore a white costume instead of the traditional red one. For a time, she joined the group of former Justice Leaguers known as the Super Buddies, in which Mary's sunny disposition was a direct contrast to the cynical, sarcastic bunch. To the world at large, Mary liked to be addressed as Captain Marvel as well, although she would sometimes accept the name Lady Marvel.
After the events of the INFINITE CRISIS, Mary Marvel lost her powers mid-flight due to magic being snuffed out in many places in the cosmic upheaval, and suffered a three-mile fall, after which she fell into a coma. During the preceding COUNTDOWN TO INFINITE CRISIS event, Mary acquired the powers of Black Adam, which resulted in her having a new, black version of her uniform. During the course of this series, Mary struggled to control her darker impulses, which came about as a result of her new powers.
During the events of FINAL CRISIS, Mary Marvel underwent an even more dramatic transformation, as she was changed by the power of Darkseid's Omega Effect into a cosmically enhanced vessel for the New God named Desaad, who was Darkseid’s most loyal servant. Once changed, Mary started to appear older, started dressing in an even darker variation of her costume, had a shaved head, and even had claws for hands. This iteration of Mary was seemingly powered by Anti-Life instead of pure magic. Eventually, she lost all of her powers and resumed her life as an average teenager.
After the events of FLASHPOINT, reality was altered once more. Mary is no longer the twin sister of Billy Batson, but is now his adopted sibling; as they are raised by the same foster parents. Not long after Billy Batson begins his heroic career as Shazam, he channels a portion of his powers directly into Mary, along with his other siblings, in a battle with Black Adam. Now presenting herself as an adult Super Hero, Mary goes by the names Mary Shazam or Lady Shazam.