Colour and format codes
Minecraft text takes codes made of a section sign (§) and one character: 0 to 9 and a to f for the 16 colours, l for bold, o for italic, n for underline, m for strikethrough, k for obfuscated (letters that keep changing) and r to go back to plain. Most plugins let you type & in place of §, since § is hard to type, and this page reads both. A colour code also switches off any format before it, so write the colour first: &a&l is bold green, while &l&a is plain green.
Putting it in server.properties
Copy the server.properties line and replace the motd= line in your server's file, then restart the server. Java Edition servers read that file as a Java properties file, which is why the § is written as \u00A7 and the break between the lines as \n; a § pasted in directly can turn into the wrong character. Text with no colour code shows in the server list's default grey.
Plugins and tellraw
The & codes version is for plugins that read &, such as Essentials, or a MOTD plugin's config. The JSON text is a text component, the form /tellraw @a and many newer plugins take; it spells out each run's colour and format, so nothing carries over by accident. Hex colours (&#RRGGBB) are plugin syntax used by Paper and Spigot plugins; turn them on only if your plugin reads them.
How much fits
The server list shows two lines, each about 270 of the game's pixels wide at its normal font. Most letters take 6 of those, narrow ones like i, l, t and the space take less, and bold adds one to every letter, so a line fits roughly 45 ordinary characters. The meter under the preview counts the way the game does, closely but not exactly for every character; anything past the limit is pushed onto the next line or cut off.
Questions
Why does my MOTD show strange characters like §?
The § was saved in a different text encoding from the one the server reads. Use the server.properties line from this page, which writes § as \u00A7, and it reads the same whatever the file's encoding.
Can I use more than two lines?
No. The server list shows two lines; anything after the second line break, or text that wraps onto a third line, is not shown.
Does the preview look exactly like the game?
No. It uses this site's own font on a dark panel, with the game's exact colours, so you can check colours, formats and length. The game's own font is narrower in places, so judge length by the meter rather than by the preview's width.
Do these codes work on Bedrock Edition?
The 16 colours and the formats work the same way, and Bedrock adds a few extra colours of its own, such as §g for minecoin gold, which Java does not have. The server.properties line here is for Java Edition servers.