We propose a quantitative electrostatic theory for a gate-confined narrow channel of the two-dimensional electron gas in the integer and fractional quantum Hall regimes. Our theory is based on the zero-magnetic-field electrostatic solution, which yields a domelike profile of electron density. This solution is valid when the width of the channel is larger than the Bohr radius in the semiconductor. In a strong magnetic field H, alternating strips of compressible and incompressible liquids are formed in the channel. When the central strip in the channel is incompressible, the conductance G is quantized in units of e2/2πLatin small letter h with stroke, i.e., there are plateaus in G as a function of the magnetic field H. However, we have found that in a much wider range of magnetic fields there is a compressible strip in the center of the channel. We also argue, based on the exact solution in a simple case, that conductance, in units of e2/2πLatin small letter h with stroke, of a short and ''clean'' channel is given by the filling factor in the center of the channel, allowing us to calculate conductance as a function of magnetic field and gate voltage, including both the positions of the plateaus and the rises between them. We apply our theory to a quantum point contact, which is an experimental implementation of a narrow channel.