Text color is obtained, usually through scripting, by using color tokens around the text to be colored. Coloring can be used in the names and descriptions of objects, and in the chat/combat log. The latter, however, has been restricted to script use since version 1.28, when BioWare started stripping color tokens from player-entered chat text.
The token that begins colored text is a 6-character sequence starting with "<c", ending with ">", and having three characters in the middle to specify the color. The three characters are read as ASCII codes, giving values from 0 to 255 for (in order) red, green, and blue. While efficient from a programming standpoint, trying to use these tokens has been difficult in practice, since the highest "normal" character, the tilde (~), is not high enough to produce bright colors. It is also a rather cryptic approach from the perspective of those unfamiliar with ASCII. The closing token is simpler, always being the 4-character sequence "</c>". This token tells the game that the remaining characters should get their default color; omitting this token at the end of text often seems to work, but it can occasionally confuse the game as to what color to use.
For example, the string "Some <c~!!>reddish</c> text" produces "Some reddish text" in the game, and uses characters easily typed. Getting a brighter red requires characters not found on a standard keyboard.
Scripting aids Edit
The biggest problem with coloring text has been the difficulty in typing characters higher than '~' into the Toolset's script editor. (Not knowing what value a particular character represents is a close second.) Several player-created aids appeared before BioWare released an #include file dealing with strings that contained a function for creating colored text.
Patch 1.69 introduced the script x3_inc_string, which contains the function StringToRGBString(). This function takes two parameters: the string to be colored, followed by a code for the color. This code is not the same as the code used within color tokens. While the code for this function is also a string of three characters, each of the characters must be a digit in the 0 to 7 range. These digits represent increasing levels of brightness, again in the order red, green, then blue. Not all colors can be produced with this function, but it is much easier to use than raw color tokens.
The same script also defines some constants representing various colors: STRING_COLOR_BLACK, STRING_COLOR_BLUE, STRING_COLOR_GREEN, STRING_COLOR_PINK, STRING_COLOR_RED, STRING_COLOR_ROSE, and STRING_COLOR_WHITE. Some of these are used to color messages associated with horse riding.
Another widely-available resource was introduced in CEP 2.1 (around the same time that patch 1.69 was released). The "scripts and blueprints" hak pak (cep2_add_sb_v1) contains the script colors_inc, which provides a number of functions for producing opening color tokens, plus one function that produces the closing token. This approach sticks closer to how color tokens are used, but still abstracts away the tricky encodings.
The general-purpose function for starting colored text in this script is ColorToken(). This function takes three integer parameters, each in the range 0 to 255. These indicate the intensity of each color, again in the order red, green, blue. There are also a number of convenience functions for producing common colors, such as ColorTokenGreen() and ColorTokenSavingThrow(). The latter produces the color used by the game when reporting the result of a saving throw to the player. There are eleven functions like the former, which specify the color to produce, and sixteen functions like the latter, which specify a type of message and produce the default color for that message type. There are also two functions for getting the names of objects wrapped in color tokens producing the colors sometimes used by the combat engine when reporting player character and non-player character names.
The closing color token is produced by ColorTokenEnd()
|ColorToken(255,0,0) + "Red" + ColorTokenEnd()||Red|
|ColorTokenBlue() + "Blue" + ColorTokenEnd()||Blue|
|ColorTokenCombat() + "Orange" + ColorTokenEnd()||Orange|
Prior to patch 1.69, the most commonly used resource for / guide to text color may have been "The Hitchhiker's Guide to Color Tokens" by gaoneng.