Color codes are used in UI design to define the color of elements such as buttons, backgrounds, and text. For red, a common color code is #FF0000, which represents full red and no green or blue. For green, #00FF00 is a typical code, indicating no red and full green with no blue. These codes are in hexadecimal format, widely used in web development and graphic design.