Our hair stands on end because when we take off our hat, the fibers of the hat’s fabric rub against the strands of our hair allowing electrons to move from our hair to the hat, generating an electric charge that doesn’t have anywhere to go (a ‘static’ charge). Our hair becomes positively charges (because it’s lost electrons) and the hat becomes negative (because it gained them)
Because our hair strands all individually positively charged, they repel each other, the same way that when we try to push the positive ends of two magnets together we feel them trying to push away. Our hair stands up as the strands are all trying to escape each other!!
There’s a video here (it’s a bit odd – be warned…):