How do I install and format new hard drive in mid-2012 Macbook pro?
This answer is more tailored to your question.


Install the new HDD.
Boot to Internet Recovery. Startup your Mac and immediately hold down the option+⌘+R key combination.
Release the keys when the Apple logo or a spinning globe appears
Use the Disk Utility application to erase the HDD. When prompted, select the "Mac OS Extended (Journaled)" format. You will also have the option to select "APFS". Some notes about APFS is given below.


The Apple File System (APFS) was introduced with High Sierra.
Many users have reported problems repartitioning their drives when APFS is in use.
Many users have report difficulties using the Boot Camp Assistant to install Windows when the APFS format is used. 
You can convert to APFS later, if you wish.

Install macOS.
Restart to the newly installed macOS.


Below is a more generic answer.


Install the new drive.
Boot to Internet Recovery. Startup your Mac and immediately hold down the option+⌘+R key combination.
Release the keys when the Apple logo or a spinning globe appears
Open a Terminal window and enter the following commands.

diskutil  unmountdisk  disk0
diskutil  eraseDisk  free  none  disk0



  Note: Normally you should not have to use the diskutil commands to erase the drive. Occasionally, step 5 fails, if step 4 is skipped. If you feel lucky, you can try omitting this step.

Use the Disk Utility application to erase the drive. When prompted, select the "Mac OS Extended (Journaled)" format. If you desire encryption, then select "Mac OS Extended (Journaled, Encrypted)" format instead.
Install macOS.


  Note: If you are installing High Sierra (macOS 10.13.x) to a SSD, this drive will probably be converted use the APFS format.

Restart to the newly installed macOS.
If the installed macOS is not the current macOS, then download and install the current macOS from the Apps Store.