One you've installed your new new hard drive, power on your Mac and immediately press and hold Command+Option+R until your device begins booting into Internet Recovery.
When prompted, select your Wi-Fi network from the list of available networks and enter its access password.
Choose Disk Utility from the Mac OS X Utilities screen.
Select your new drive from the list of devices on the left.
Choose the number of partitions you'd like for the device from the Partition layout dropdown, name the partition, and ensure its format is Mac OS Extended (Journaled). We'll create '1 Partition' with the name Macintosh SSD.
Click the Options button and make sure GUID Partition Table is selected then click the OK button.
Click the Apply button then click the Partition button to confirm you want to partition the drive.
Select Quit Disk Utility from the Disk Utility menu at the top left corner of the display.
Choose Reinstall Mac OS X from the Mac OS X Utilities menu.
Click Continue to launch the installation wizard.
You'll be notified that Apple will verify your eligibility to download and restore Mac OS X. Click Continue.
Agree to the software licensing agreement.
Select your new hard drive and click Install.
Your computer will now download Mac OS X and install it. Note that only the version of OS X your computer shipped with will be installed at this time. To get to the latest version of macOS you will update using the Mac App Store.