The term Toprail refers to the attachment rail on top of the weapon. This is usually used for optics/sights or laser/flashlights. Since these usually have a Picatinny mount, a rail of this type is usually used as toprail. Of course there are exceptions (e.g. the first versions of the L85 with the mounting rail for the SUSAT), but these are rare. KeyMod and M-LOK hardly make sense at this point, as they currently require a Picatinny adapter. These systems are often used for hand guards on the sides and at the bottom.
Umarex/Ares H&K G36c Handguard with KeyMod at the sides
Not all weapons are directly equipped with a toprail. The MP5 series does not have such a toprail ex works, but it can easily be attached later.
With some weapons also a part of the sights is built into the Toprail (mostly the Front Sight). Another example would be the HK 417, where the Flip-Up Front Sight was integrated directly into the hand guard.
Continuous & Interrupted Toprail
A distinction can be made between a continuous and an interrupted rail. The extreme example of an interrupted toprail is an M4 A1 with a classic KAC quadrail system. But also the first versions of newer weapons (MK18 or also HK 416 & 417) had a slightly interrupted toprail. For example, the H&K 417 Sniper had a transition at the crossing between body and hand guard where no accessories could be mounted.