mRNA is formed with the help of the codes of the DNA.
Formation of RNA from codes written on DNA is known as transcription, where DNA double helix unzips and unwinds.
Then there are free ribonucleotides which pair up with the complementary bases of one of the exposed DNA strand.
The sugar and phosphate of the neighbouring ribonucleotides keep joining and sugar phosphate backbone of RNA is formed. This pairing up of complementary ribonucleotides along bases of DNA strand is monitored by RNA polymerase , an enzyme.
As at the end of this pairing up process, a new single stranded RNA is formed. The newly formed RNA may undergo processing and will later be used for protein synthesis, i.e. translation.
The video below provides a summary of how the processes of transcription and translation occur using the Shockwave tutorial DNA Workshop from PBS.