How it Works
Calculated columns in SharePoint that have the type “number” can render HTML via a concatenate formula. I used a choice column with red, yellow, and green in a dropdown, but any HTML colors will work for the color selection. Then I made a formula that creates a square div and uses that same color as the background color in the CSS like this:
=CONCATENATE("<div style=",CHAR(34),"height:20px;width:20px;border-radius:3px;background-color:",[Color],CHAR(34),"> </div>")
The CHAR(34) bits are the mechanism for inserting quotations in a concatenate formula (they are used in the CSS), the [Color] is the color value from the choice column. As long as you provide choices that are valid HTML color names, this will color your box according to whichever option is selected!
To create this from scratch, create a custom list or a task list, then add a “choice” column with color names from the color list linked above. Making it required is a good idea. Then add a calculated column number type column, paste in the formula above, and replace the
[Color] value with your choice column name.
Make sure your new calculated column is displayed in your list view (you may want to hide the text color value and just leave it in the form, too). Remember that you can save the list as a template for use in other sites.
Here’s an example with more colors from the web color list!
SharePoint likes to make number calculated columns align right… the alignment is done via align tags in the HTML, and I can’t figure out how to get it to align left or center instead. Making your column name short will make the alignment less noticeable (note column name above follows this rule – “Tag”).