To address the accuracy limitations of existing safety helmet detection algorithms in complex environments, we propose an enhanced YOLOv8 algorithm, called YOLOv8-CSS. We introduce a Coordinate Attention (CA) mechanism in the backbone network to improve focus on safety helmet regions in complex backgrounds , suppress irrelevant feature interference, and enhance detection accuracy. We also incorporate the SEAM module to improve the detection and recognition of occluded objects, increasing robustness and accuracy. Additionally, we design a fine-neck structure to fuse features of different sizes from the backbone network, reducing model complexity while maintaining detection accuracy. Finally, we adopt the Wise-IoU loss function to optimize the training process, further enhancing detection accuracy. Experimental results show that YOLOv8-CSS significantly improves detection performance in general scenarios, complex backgrounds, and for distant small objects. YOLOv8-CSS improves precision, recall, [email protected], and [email protected]:0.95 by 1.67%, 5.55%, 3.38%, and 5.87%, respectively , compared to YOLOv8n. Our algorithm also reduces model parameters by 21.25% and computational load by 15.89%. Comparisons with other mainstream object detection algorithms validate our approach’s effectiveness and superiority.