שולחן ערוך
אנהגו בבמנין השיטין לכתוב בשל יד שבעה שיטין בכל פרש' ובשל ראש ארבעה שיטין גואם שינה לא פסל:
It has become the accepted practice, regarding the number of lines written in the tefillin parshiyos, to write seven lines in each passage of the hand-tefillin (which holds all four passages on a single piece of parchment), and to write four lines for the head-tefillin (where each of the four passages is on its own parchment). But if one deviated from this customary number of lines, the tefillin are not thereby rendered invalid.
משנה ברורה
(א) נהגו - ע"פ הקבלה ביד סופרים איש מפי איש (טור):
(1) 'It has become the accepted practice' — The Mishnah Berurah explains that this line-count is based on a tradition (kabbalah) handed down among the scribes, one man from the mouth of another, going back through the generations. [Tur]
(ב) במנין השיטין - וכן יש קבלה בידם בענין התחלת ראשי השורות בשל יד ובשל ראש כמבואר בטור ובב"י וסופרים כהיום אין מדקדקין בתחלת ראשי השורות ומשנים כאשר יזדמן להם והרוצה לדקדק לא ימשוך אותיות או יקצר הרבה כדי לכוין ראשי השיטות כי אין נוי לתפילין אבל מעט רשאי (פמ"ג):
(2) 'Regarding the number of lines' — So too there is a tradition in their hands concerning where the tops of the lines should begin — that is, with which letter each line opens — both in the hand-tefillin and in the head-tefillin, as is explained at length in the Tur and in the Beis Yosef. Scribes nowadays, however, are not particular about the letters that begin the tops of the lines, and they change them as it happens to work out for them. One who does wish to be exact should not, for the sake of aligning the beginnings of the lines, stretch out letters or compress them a great deal, for such distortion is no adornment for the tefillin; a slight adjustment, however, is permitted. [the Pri Megadim]
(ג) ואם שינה - בין בשל יד ובין בש"ר ואם אין לו לש"י רק קלף קצר וארוך שאין יכול לכתוב עליו שבע שיטין אם לא שיכתוב כתיבה דקה מאד נראה דטוב יותר לשנות מנין השיטין עיין במרדכי בהלכות קטנות סוף ה"ת והובא לעיל סימן ל"ב דבכלל זה אלי ואנוהו לכתוב כתיבה גסה במקצת שלא יהיו נמחקין מהרה. ובאמת אנו רואין בחוש דבכתיבות הדקות שרגילין איזה סופרים כהיום בעו"ה מצוי כמה וכמה קלקולים גם בתחילת כתיבתן שלא נכתבו כדינן מחמת דקותן וברובם חסר כמה וכמה תגין דשעטנ"ז ג"ץ דהוא מדינא דגמרא ויש מהראשונים שמחמירין בזה אפילו בדיעבד ושומר נפשו לא יקנה פרשיות כאלה בתוך תפיליו אם לא שיבדוק אותם מתחילה היטב היטב וידע מי כתב הפרשיות דפרשיות כאלו מצוי מאד דכותביהן הם עדיין נערים שלא ידעו כלל דיני כתיבת סת"ם:
(3) 'But if one deviated' — This applies both to the hand-tefillin and to the head-tefillin. And if for the hand-tefillin one has only a piece of parchment that is short and narrow, on which he cannot manage to write seven lines unless he writes in a very fine, tiny script, it seems that it is better to change the number of lines than to resort to such fine writing. See the Mordechai in Hilchos Ketanos at the end of the Laws of Tefillin, cited earlier in Siman 32, that included in the principle of 'This is my God and I will beautify Him' is to write in a somewhat bold, substantial script, so that the letters will not be erased quickly. And in truth we see plainly that with the fine writing which some scribes are accustomed to use nowadays, in our many sins, many defects are common — even at the very outset of their writing the letters were not formed in accordance with their law, because of their fineness, and in most of them many of the crowns (tagin) of the letters shatnez getz are missing, which is a requirement from the law of the Gemara. And some of the Rishonim are stringent about this even after the fact (bedi'avad). One who guards his soul will therefore not purchase such passages to place inside his tefillin unless he first examines them very, very well, and knows who wrote the passages — for such passages are very commonly found, since those who write them are still youths who do not yet know at all the laws of writing sacred scrolls (Sifrei Torah, Tefillin, and Mezuzos).