Why does my iphone heat up sometimes?

I was watching youtube when I realized that my phone was getting warm. When I took off the cover and held the phone it was even hotter than maybe 100 degrees because in comparison to my forehead temp when I have a fever, the iphone was even hotter than that. Why does this happen? How to I fix it?

Your phone is getting hot since the processor is working to render video's on the screen. This is normal if you have been watching video's for an extended period of time. A temperature of 100 F° is within normal operating temperature. If it starts to go to much over that though, then that is bad. However iPhone's usually have a built in fail safe. If the phone get's to hot the phone will pop up a message on screen stating that the device is hot. And in turn it will likely either throttle apps and services on the phone to lessen the load, or it will not let you play any more content on the device till it cools down. If it's damagingly hot, it will shut off entirely so the phone doesn't fry it's internals. Most phones have a built in software fail safe. It's best to always keep your phone off of soft material and to allow it to have ventilation. Keep it off a bed where it could get smothered by bed sheets. Remember your phone has a lithium ion battery. And they can get to hot and explode causing a fire hazard if the phone get's to warm. It's a very low risk. And the phone will usually shut down before it get's to hot. But sometimes a fail safe isn't a 100% guarantee. Just keep it in a place where the air in the room can reach all sides of the phone while you're holding it. And this way you won't need to worry.