A team of writers contributed to this track: the Swedes Oscar Holter and Jakke Erixson, and the Americans Savan Kotecha, Bonnie McKee and Oliver Goldstein. Max Martin and his co-producer Shellback also received writer credits, bringing the total number of writers to seven.
According to McKee, the song was intended for Miley Cyrus. "She had come in and Max and I had written the song already," McKee told Songfacts in 2019
. "She came in and heard it, and she wanted to rewrite some things and change a bunch of stuff. Miley wasn't as established as she is today, so Max was like, 'No, we're not going to change this lyric. We think it's perfect and we love it.' So, it didn't end up working out with Miley, but then when we got Christina on it, I was really thrilled because I grew up listening to Christina, and she really did it justice. I think Miley could have absolutely done it justice too, but it was just exciting to have Christina on my resumé."
"The way that she emotes on that song really brings it to life," McKee added. "I wish it would've been a single. I thought it would be - it seems like such a no-brainer song, but that was one of the ones that got away I guess."