i just read a post which was talking briefly about getting virus's from websites, how do you recieve a virus from a website? is it common and how do you prevent it from happening.

when you connect to a website you get to reach their site by travelling to the appropriate IP. which will automaticaly give the site my IP. how would a virus be uploaded to my pc? is there some kind of malitious code in the html or are hidden packages sent through ports? what ports would these be? and are there programs out there that allow to see exactly what files & data are being transfered.

the more feedback the better, im trying to be quite vague about this subject so i can get as much of a general understanding as possible