O-linked N-acetylglucosamine (O-GlcNAc) is a prevalent protein modification that plays fundamental roles in both cell physiology and pathology. O-GlcNAc is catalyzed solely by O-GlcNAc transferase (OGT). The study of protein O-GlcNAc function is limited by the lack of tools to control OGT activity with spatiotemporal resolution in cells. Here, we report light control of OGT activity in cells by replacing a catalytically essential lysine residue with a genetically encoded photocaged lysine. This enables the expression of a transiently inactivated form of OGT, which can be rapidly reactivated by photo-decaging. We demonstrate the activation of OGT activity by monitoring the time-dependent increase of cellular O-GlcNAc and profile glycoproteins using mass-spectrometry-based quantitative proteomics. We further apply this activation strategy to control the morphological contraction of fibroblasts. Furthermore, we achieved spatial activation of OGT activity predominantly in the cytosol. Thus, our approach provides a valuable chemical tool to control cellular O-GlcNAc with much needed spatiotemporal precision, which aids in a better understanding of O-GlcNAc function.