Context. O stars are excellent tracers of the intervening ISM because of their high luminosity, blue intrinsic SED, and relatively featureless spectra. We are currently conducting the Galactic O-Star Spectroscopic Survey (GOSSS), which is generating a large sample of O stars with accurate spectral types within several kpc of the Sun. Aims. We aim to obtain a global picture of the properties of dust extinction in the solar neighborhood based on optical-NIR photometry of O stars with accurate spectral types. Methods. We have processed a carefully selected photometric set with the CHORIZOS code to measure the amount [E(4405 − 5495)] and type [R5495] of extinction towards 562 O-type stellar systems. We have tested three different families of extinction laws and analyzed our results with the help of additional archival data. Results. The Maíz Apellániz et al. (2014, A&A, 564, A63) family of extinction laws provides a better description of Galactic dust that either the Cardelli et al. (1989, ApJ, 345, 245) or Fitzpatrick (1999, PASP, 111, 63) families, so it should be preferentially used when analysing samples similar to the one in this paper. In many cases O stars and late-type stars experience similar amounts of extinction at similar distances but some O stars are located close to the molecular clouds left over from their births and have larger extinctions than the average for nearby late-type populations. In qualitative terms, O stars experience a more diverse extinction than late-type stars, as some are affected by the small-grain-size, low-R5495 effect of molecular clouds and others by the large-grain-size, high-R5495 effect of H II regions. Late-type stars experience a narrower range of grain sizes or R5495, as their extinction is predominantly caused by the average, diffuse ISM. We propose that the reason for the existence of large-grain-size, high-R5495 regions in the ISM in the form of H II regions and hot-gas bubbles is the selective destruction of small dust grains by EUV photons and possibly by thermal sputtering by atoms or ions.