Yes, defragging is safe for a traditional hard disk drive (HDD). If you’re unsure whether you have a solid state drive (SSD) or HDD, Windows will tell you whether you’re using a HDD or SSD in the media type column. Defragging is safe and beneficial for improving data access performance for HDDs that store information on disk platters.
If you have an SSD, there is no need to defrag the disk.