Modern electronics are founded on switching the electric signal by radio frequency (RF) electromagnetic fields on the nanosecond timescale, limiting the information processing to the gigahertz speed. Recently, optical switches have been demonstrated using terahertz and ultrafast laser pulses to control the electric signal and enhance the switching speed to the picosecond and a few hundred femtoseconds time scale1-13. Here, we exploit the reflectivity modulation of a dielectric system in a strong light field to demonstrate the optical switching (ON/OFF) with attosecond time resolution. Moreover, we present the capability of controlling the optical switching signal with complex synthesized fields of ultrashort laser pulses for data binary encoding. This work paves the way for establishing optical switches and light-based electronics with peta- and exahertz speeds, several orders of magnitude faster than the current semiconductor-based electronics, opening a new realm in information technology, optical communications, and photonic processor technologies.