The stability and postcritical behaviour of a horizontal flag undergoing gravity-induced deformation and periodic contact with a nearby horizontal rigid wall are experimentally investigated. The results elucidate the combined effects of gravity and contact on flutter, and reveal design principles for application to triboelectric energy harvesting. By varying the free-stream velocity, flag thickness and distance between the flagpole and the wall, the dynamics of the flag are classified into quasistatic equilibrium, flutter, partial contact and saturated contact modes. Considering the significance of gravitational effects, a new dimensionless flow velocity is proposed to identify the distribution of the dynamic modes, and its definition varies according to whether the wall is placed above or below the flag. The critical conditions for transitions between the dynamic modes are determined from the balance of fluid dynamic and gravitational effects. The distance from the flagpole to the wall is found to be more critical for transitions in the lower-wall configuration than in the upper-wall configuration. The peak contact force as well as the oscillation amplitude and frequency at postequilibrium exhibits remarkably different trends depending on the location of the wall. The peak contact force imposed on the wall by the fluttering flag weakens as the distance to the wall increases in the case of an upper wall, whereas it becomes stronger in the case of a lower wall.