Stella Grant, a senior in high school, checks herself into the hospital after coming down with a fever and sore throat. Stella was diagnosed with cystic fibrosis when she was six years old and knows these symptoms can be life-threatening. Stella has a strict regimen of treatments and medication, which she follows religiously so that she will not become sick and lose her spot on the lung transplant list. Her determination to stay alive and healthy stems from not wanting her parents to suffer further, as they divorced after Stella’s sister Abby died the previous year. Stella’s friend Poe, whom she has known since she was first diagnosed, is also in the hospital. Stella meets a new cystic fibrosis patient on the same floor, Will Newman, who has the serious complication of B. cepacia, which is almost always fatal. Though Stella initially finds Will attractive, she is immediately put off by Will’s defiance of the hospital’s rules. Stella plans to stay far away from Will, which she must do anyway as patients with cystic fibrosis cannot come within six feet of each other to avoid cross-contamination of bacteria. Will, who will turn eighteen in two weeks, believes he will die soon from his illness and plans on stopping treatment once he is of age so that he can travel.

In spite of herself, Stella becomes frustrated by Will’s refusal to follow a regimen and asks if she can help him. The two begin taking their medication together over Skype and getting to know each other better. Once Will discovers that Stella’s sister has died, he tries to talk to her about it, but she becomes angry and refuses to talk to him. Stella develops an infection on the skin around her feeding tube, and Dr. Hamid, who treats Stella, Poe, and Will, says she will need surgery to replace the tube. Will realizes that this will be Stella’s first surgery without Abby and sneaks into the pre-op room to comfort her. At this point, Stella realizes she is in love with Will. After Stella goes into surgery, Barb, one of Stella’s nurses, catches Will and reminds him that his presence near Stella could kill her. Will feels guilty, and although Stella tries to contact Will after her surgery, he has Poe deliver the message that they cannot be together.

Stella, furious at all that her illness has taken from her, decides that she and Will are taking something back. She tells Will they will remain five feet apart instead of six. That night, they go on a “date” around the hospital, using a pool cue to make sure there is five feet of space between them at all times. The next day is Will’s eighteenth birthday, and Stella plans a scavenger hunt that leads to a surprise party for him. While they are eating in the cafeteria with the friends Stella has gathered, Barb comes in and orders Stella, Will, and Poe back to their rooms. That night, Poe dies suddenly. Stella becomes distraught and at first pushes Will away, both literally and figuratively. Later, Stella tells Will they are going to walk to a park a few miles from the hospital that has holiday lights she enjoys looking at.

As Stella and Will walk to the park, they come across a frozen pond and spin around on it. After losing Poe, Stella does not want to put her life on hold any longer, and she and Will finally embrace. Will tells Stella that he loves her. However, Stella receives a text that her new lungs are on their way. She at first doesn’t tell Will, as she no longer plans on taking the lungs and would rather be with Will. But Will also receives a message with the same information and urges Stella to accept the lungs. While arguing with Will, Stella trips and falls onto the ice, which breaks, and Stella plunges into the freezing water. Will jumps in and pulls Stella out. They are taken back to the hospital, where Will convinces Stella to take the lungs. While Stella is in surgery, Will realizes that his presence will only ever bring Stella harm. After she wakes up, he stands in the courtyard outside her room with the lights from the park strung up. Over the phone, Will tells Stella goodbye and then walks away.

Eight months later, Will is on his way to Brazil, and Stella is on her way to Rome. Stella’s health has improved with her new lungs, and while Will remains sick, he sticks to his regimen. At the airport, Stella and Will lock eyes and approach one another, making sure they stand five feet apart.