The Shulchan Aruch · Yoreh De'ah
יורה דעה רפ״חYoreh De'ah 288
Siman 288 of 402 in Yoreh De'ah — 15 se'ifim
Se’if 1א׳
כֵּיצַד כּוֹתְבִין אֶת הַמְּזוּזָה, כּוֹתְבִין שְׁתֵּי פָּרָשִׁיּוֹת שְׁמַע (דְּבָרִים ו, ד ט) וְהָיָה אִם שָׁמוֹעַ (דְּבָרִים יא, יג כא) עַל דַּף אֶחָד בִּירִיעָה אַחַת, וְעוֹשֶׂה לָהּ רֶוַח מִלְּמַטָּה וְרֶוַח מִלְּמַעְלָה כְּמוֹ חֲצִי צִפֹּרֶן, וּבִתְחִלָּתָהּ יְשַׁיֵּר כְּדֵי לָגֹל אוֹתָהּ אַחַר שֶׁתִּכָּרֵךְ. וּבְסוֹפָהּ אֵין צָרִיךְ לְהַנִּיחַ כְּלָל (טוּר).
With what, and how, it is written. How is the mezuzah written? He writes two sections on one pane (daf) in a single sheet (yeri`ah): Shema` and Vehayah im-shamo`a. He leaves a space below and above, approx. half a pinkly-fingernail-width (tziporen). When beginning he should measure in order [to leave a top margin] to enable unrolling it after it's rolled. Rem"a: At the bottom he needn't leave any margin. (Tur)
Se’if 2ב׳
צָרִיךְ לְכָתְבָהּ בְּדַף אֶחָד. וְאִם כְּתָבָהּ בִּשְׁנַיִם אוֹ בְּג' דַּפִּין, כְּשֵׁרָה.
It should be written in one [column] (daf) but if he wrote it on two or three [columns] it's kosher.
Se’if 3ג׳
כְּתָבָהּ שֶׁלֹּא עַל הַסֵדֶר, אֲפִלּוּ שָׁכַח מִלִּכְתֹּב אוֹת אַחַת, פְּסוּלָה וְאֵין לָהּ תַּקָּנָה. וְאֵין צָרִיךְ לוֹמַר אִם הִקְדִּים פָּרָשָׁה לְפָרָשָׁה.
If he wrote out of order, even if he forgot one letter, it's invalid and irreparable; needless to say if he put the wrong paragraph first.
Shulchan Aruch, Yoreh De'ah — Torat Emet 357 edition, via Sefaria — public domain
English: Shulchan Aruch, Wikisource, via Sefaria — CC BY-SA