An optosensor includes an optoreflector (1) having a light emitting element (12) and a light receiving element (13) which are mounted on a substrate (11), a light transmitting resin (15) sealing the light emitting element (12) and the light receiving element (13), and a light blocking resin (2), and optionally further includes a light transmitting cover (20) that is disposed to face a light emitting/receiving portion of the optoreflector (1). In the optosensor, a light blocking wall (2a) and an eave (2b) are formed between the light emitting element (12) and the light receiving element (13) with the light blocking resin (2), the cave (2b) being linked to the light blocking wall (2a) to narrow an upper light emitting surface of the light emitting element (12).