The relationship between trade and environmental quality is a major controversial issue. The paper intends to provide robust evidence and new insights into the discussion. Specifically, it examines the effect of trade on carbon dioxide emissions (CO2) systematically in a North-North, North-South, South-North, and South-South context. It employs a panel data instrumental-variable quantile approach to control for endogeneity and account for potential (quantile) parameter heterogeneity. Some important results emerge. First, trade with the North increases CO2 emissions whereas trade with the South mitigates CO2 emissions with a relatively larger effect for less polluted host countries. Second, for advanced countries, their trade with the South or the North leads to a reduction in CO2 emissions, the effect that seems relatively stronger for less polluted advanced countries. Third, for developing countries, their trade with the North worsens CO2 emissions whereas their trade with the South mitigates CO2 emissions with a larger effect for less polluted developing countries. Last, the environmental Kuznets hypothesis is also detected across quantiles for the full sample and both developing and advanced countries subsamples. The findings suggest that trade benefits the advanced countries but could hurt the developing countries when trade with high-income trading partners occurs, in terms of CO2 emissions.