I highly recommend you make a bootable macOS 10.13 USB installer now while you still can. In theory you should be able to boot into Recovery Mode, but if something goes wrong then your options are limited.
How to create a bootable installer for macOS - Apple Support
In order to erase the drive you need to be booted from a macOS installer. Then launch Disk Utility, click "View" and select "Show All Devices" so that the physical drive appears on the left pane of Disk Utility. Select the physical drive and erase it as GUID partition and APFS (top option). You could also just select the MacOS Extended (Journaled) file system since the installer will automatically convert the drive to APFS during the install process.
If your iMac uses a Fusion Drive, then just select the Fusion Drive item and erase it instead.
If your iMac has a hard drive (or Fusion Drive), then I highly recommend first enabling Filevault and let the encryption process finish before attempting to perform the clean install so that all data on the drive is destroyed. This is not necessary if the iMac is only using an Apple SSD (not sure about a third party SSD). Apple's instructions assume Filevault is enabled or an SSD is being used.
Also, here is some other things you may need to do before selling or giving away an old Mac:
What to do before you sell, give away, or trade in your Mac - Apple Support