Epoxy resins infiltrate into every inch of our life and its fire safety always being the vital concern due to the intrinsic flammability. Commercial flame-retardants, including inorganic particles and organic small molecules, commonly cause problems like reduced transparency, worse mechanical properties, and leakage with time. To address these issues, nitrogen-phosphorus polymer with conjugate structure is proposed and synthesized. Specifically, a de novo synthetic melamine-formaldehyde polymer with diphenylphosphinic side groups showed good compatibility with epoxy precursor and improved the UL-94 level of the commercial epoxy resin from no rating to V-0, and significantly suppressed the smoke releasing at a weight ratio of 4% without deteriorating its mechanical properties. The migration of the polymer was also evaluated to be stably localized in the matrix. Our study provided a simple and effective way to customize the flame-retardant for transparent epoxy resin, which will inspire the development of nitrogen-phosphorus polymers for other matrixes.