Pieces of text
A message is made of pieces. Each piece has its own colour (one of the 16 or any hex colour), formats, and optionally a click action and hover text, so one word can run a command while the rest of the line does nothing. Inside a piece you can also type & codes, like &a for green and &l for bold, to change colour part way through. The pieces are joined in order with nothing between them, so put the spaces in the text.
Click actions and hover text
Run a command runs it as the player who clicks; in chat and books that is with their own permissions, so it is good for /trigger and teleports an operator sets up; commands that send a chat message, like /say and /msg, cannot run from a click. Suggest a command puts it in the chat box to edit. Open a link asks the player before opening it, and the link must start with http:// or https://. Copy text puts the text on their clipboard, and Go to a page only works in books. Hover text shows when the pointer is over the piece.
Which version
Before 1.21.5 the text is JSON, {"text":"Hi","clickEvent":{"action":"run_command","value":"/help"}}. From 1.21.5 it is SNBT, {text:"Hi",click_event:{action:"run_command",command:"/help"}}: the events are renamed and each action names its own field (command, url, page), and hover text moves from contents to value. Signs and books written with /give also changed in 1.20.5, when item NBT became components. From 26.3, a sign only runs click events when it carries allow_op_features:true, which this page adds when a line has a click. Checked against Java Edition 26.3.
Titles, signs and books
Title writes a /title command for each part you use: the big title, the subtitle under it and the action bar above the hotbar. The subtitle only shows when a title is sent, which is why it comes first, and the times set how long the fade in, stay and fade out take. Sign gives a /setblock to place the sign with its text and a /give for a sign item that keeps it; each piece goes on a line of the front or back, and a line holds about 90 of the game's pixels, roughly 15 letters. Book gives a written book: pick each piece's page, and set the title (up to 32 characters) and author.
Copying it out
Each command has its own Copy button and a count of its characters. The chat box takes 256, so longer commands go in a command block or a function file. For Bedrock Edition the chat and title outputs add a rawtext version, which keeps the colours and formats as § codes but has no click or hover events. The preview uses this site's own font with the game's colours. Nothing you type leaves this page.
Questions
Why does my tellraw say "Expected key" or "Invalid chat component"?
It was written for another version. Text with quoted keys, {"text":...}, is for 1.21.4 and earlier; from 1.21.5 the game reads SNBT, and the event names changed. Pick your version at the top and copy again.
Can a click run a command for players who are not operators?
A click runs the command as the player who clicked, so it only works if they could type it themselves. /trigger is made for this: an operator sets up a scoreboard objective, and any player can run /trigger on it.
Why does nothing happen when I click my sign?
From 26.3, signs ignore click events unless they have allow_op_features:true, which only an operator can set; place the sign with the /setblock command here. In earlier versions, right-clicking runs the click events on the side you are facing.
Can I use hex colours?
Yes, in Java Edition from 1.16. Pick Hex colour in a piece's colour list, or type &#RRGGBB in the text. Bedrock Edition has only the 16 colours, so its rawtext uses the nearest.
How much fits on a book page?
About 14 lines of roughly 19 characters, depending on the letters. Text that does not fit is cut off at the bottom of the page, so split long text over more pages.