Bacteria are often classified into Gram-positive and Gram-negative strains by staining with crystal violet (CV). The described bioorthogonal modification of CV with trans-cyclooctene (TCO) can be used to render Gram-positive bacteria magnetic with tetrazine-functionalized magnetic nanoparticles (MNP-Tz). This method allows class-specific automated magnetic detection and magnetic separation.