An optical sensor includes a flexible substrate, a light emitting element, and a light receiving element. The light emitting element and the light receiving element are mounted on element mounting portions and connected to element connection portions by wires. The optical sensor also includes through wirings extending through the substrate. Each through wiring is bonded to the element mounting portion or the element connection portion. The through wirings include a heat radiation through wiring that is located immediately below the light emitting element and bonded to the element mounting portion on which the light emitting element is mounted. The optical sensor further includes light shielding materials and encapsulation resins for surrounding and encapsulating the light emitting element and the light receiving element, respectively.