The electronic and optical properties of porous silicon are studied through first-principles pseudopotential calculations within the local-density functional approximation. To find the origin of photoluminescence, H-terminated silicon wells and wires are employed. We find that highly efficient and visible luminescences of porous silicon result from the quantum confinement effect and the surface-related features. Relatively localized states at the surfaces give strong optical transitions. The role of the hydrogen-passivated surfaces is emphasized.