The Lagrange-mesh method is an approximate variational calculation which resembles a mesh calculation because of the use of a Gauss quadrature. The hydrogen atom confined in a sphere is studied with Lagrange-Legendre basis functions vanishing at the center and surface of the sphere. For various confinement radii, accurate energies and mean radii are obtained with small numbers of mesh points, as well as dynamic dipole polarizabilities. The wave functions satisfy the cusp condition with 11-digit accuracy.