Rapid and sensitive detection of the concentration of sialic acid (SA) in serum is crucial for early tumor screening and prognostic assessment; however, it still remains challenging. Here, we propose a novel kind of hydrogel grating sensor with boron affinity and molecular imprinting effects (B-MIP) for the rapid and sensitive detection of SA concentration in serum. The hydrogel gratings feature uniform surface relief microstructures and incorporate highly specific recognition binding sites into SA molecules provided by boron affinity and molecular imprinting. The periodic nanoridges of hydrogel gratings increase the specific surface area contacting the environmental solution; therefore, fast detection can be achieved within 2 min. Upon recognition of SA molecules, the height of hydrogel gratings changes at the nanoscale, causing a change in the diffraction efficiency of the hydrogel gratings. The B-MIP hydrogel grating sensors have highly specific binding sites to SA molecules distributed throughout the whole hydrogel and can preferentially and selectively recognize and respond to the SA molecules even in the presence of interference substances glucose and fructose with high concentrations. The B-MIP hydrogel grating sensors are effectively applicable for the rapid and sensitive detection of SA concentrations in real serum samples with satisfactory accuracy and precision. Our approach provides an excellent strategy to address the current challenges in SA detection and provides new insights into the detection of tumor markers in serum, thereby opening up new ways to accurately detect complex biological samples in analytical science.