Understanding the dynamics of mass exchange between a street canyon and the overlying atmosphere is crucial to predict air quality in urban areas. Despite the large number of studies on this topic, there are many aspects that still need to be clarified. Among these, one is certainly the role of thermal stratification in street canyon ventilation. In order to fill this gap, this study evaluates how the combined effect of street canyon geometry, wall roughness and differential heating of the building facades influences pollutant dispersion within the canyon and out of it. The study was carried out in a wind tunnel, adopting an idealized urban geometry made up of square bars placed normal to the wind direction. The boundary conditions inside the canyon were modified by heating its windward and leeward walls, by changing its aspect ratio and by introducing roughness elements at the walls. A passive scalar was injected from a line source at ground level. The flow and concentration fields were measured in a cross‐section of the canyon. Characteristic exchange velocities within the canyon and towards the external flow were estimated comparing the experimental data with an analytical model for the cavity wash‐out. Results show that the transition from one recirculating cell to two counter‐rotating cells inhibits canyon ventilation, with a consequent increase in pollutant concentration at the pedestrian level. This transition occurs as the cavity aspect ratio increases and is facilitated by adding roughness elements at the windward wall. Heating the leeward wall has negligible effects on canyon ventilation. Heating the windward wall accelerates pollutant removals in square cavities, while it contributes to a worsening of air quality in narrow cavities. Finally, the wash‐out times of the cavity are discussed in terms of a relative contribution of the mean advective motion and its turbulent counterpart.