Hartnett was born in Saint Paul, Minnesota, and was raised by his father, Daniel Hartnett, a building manager, and his stepmother, Molly, an artist. He has three younger half-siblings. He is of mainly Irish ancestry and was raised Roman Catholic, attending Nativity of Our Lord Catholic Grade School, where he played Adam Apple in an eighth grade production of "Krazy Kamp". He later attended Cretin-Derham Hall High School before switching to South High School in Minneapolis, Minnesota, from which he graduated in June 1996.
Hartnett was active in sports as a child, especially football, and did not entertain the thought of becoming a performer, until an injury left him unable to participate on the athletic playing field. A relative encouraged him to audition for a stage production of Tom Sawyer at Youth Performance Company and to his surprise, he won the part of Huckleberry Finn. Now in love with the stage, he went on to star in a slew of high school plays.