The width effect on contact angle hysteresis in a microchannel with patterned heterogeneous surfaces is systematically investigated. In the model, identical defects periodically appear on the background surface. To this end, a droplet's evaporation and condensation processes inside the microchannel are studied by theoretical analysis and numerical simulation based on a diffuse-interface lattice Boltzmann method. The microchannel width effect on the system's equilibrium properties is studied. The results demonstrate that the number of equilibrium configurations increases linearly with the microchannel width ( $b$ ), and has a quadratic relationship with the cosine of the reference contact angle and the heterogeneity strength ( $\varepsilon$ ). The average most stable contact angle is independent of $b$ and is always equal to the contact angle predicted by the Cassie–Baxter equation. For contact angle hysteresis ( $H$ ), when the microchannels are narrow and wide, there are individual-effect-dominated hysteresis (IDH) and collective-effect-dominated hysteresis (CDH), respectively. The IDH and CDH are hysteresis modes corresponding to the jumping behaviour of contact lines affected by individual defects and two neighbouring defects, respectively. Based on the graphical force balance approach, we establish a scaling law to quantify the connection between $H$ , $b$ and $\varepsilon$ . Specifically, in the IDH mode, $H\sim b \varepsilon ^2$ , while in the CDH mode, $H$ increases linearly with $\varepsilon$ but nonlinearly with $b$ .