Three key styles, one rule for values
Bare keys
The default. letters_and_underscores_only_123. Allowed: A-Z a-z 0-9 _ -. No spaces, no dots, no special characters.
Quoted keys
Wrap in double or single quotes for special characters or spaces. "key with spaces" = "value". Same escape rules as basic strings.
Dotted keys
A dot in the key path creates nesting: server.host = "localhost" is shorthand for [server] + host = "localhost". Each segment of the dotted path follows the bare/quoted rules: servers."my-host".port = 8000 works.
One key per name
TOML rejects duplicate keys at the same level — name = "a"\nname = "b" is a parse error. (Compare with JSON: undefined behavior. YAML: usually 'last wins'.) This is on purpose; ambiguity-free configs are TOML's selling point.
The 'dotted key vs table' subtlety:
a.b = 1 and [a]b = 1 produce the same parsed value but interact differently with later [a] blocks. Modern TOML allows mixing, but if you redefine [a] after writing a.b = 1, you get a 'cannot redefine table' error. Pick one style per logical section.