A firewall does not "block all ports" - otherwise you could just pull a cable instead of having some firewall. Instead simple firewalls block all incoming connections (what you read as all ports blocked) but allow all outgoing connections - and in the case of web surfing the connections are initiated from inside and are thus outgoing.
Most firewalls today are stateful, which means that they keep internal states for established connections or connections which are in the process of getting established. Any incoming data are matched against this state table and if there is a matching state the data are passed from outside to inside. Any other outside data which don't match any state are discarded.
This way a firewall allows the internal browser to establish a connection to an external site and allows the response from the external site to get passed back to the browser through the firewall. And at the same time it discards any other data from outside, i.e. "all ports closed".