C# Color Table

Color type

Many HTML and system colors are available. We can enumerate these in the C# language and the ASP.NET Framework. We build a table containing all named colors, making HTML easier to write.

Note:Here we see the HTML colors in a table generated using the C# language. Afterwards we see the code that wrote the table.

HTML color table

activeborder        
activecaption       
activecaptiontext   
aliceblue           
antiquewhite        
appworkspace        
aqua                
aquamarine          
azure               
beige               
bisque              
black               
blanchedalmond      
blue                
blueviolet          
brown               
burlywood           
buttonface          
buttonhighlight     
buttonshadow        
cadetblue           
chartreuse          
chocolate           
coral               
cornflowerblue      
cornsilk            
crimson             
cyan                
darkblue            
darkcyan            
darkgoldenrod       
darkgray            
darkgreen           
darkkhaki           
darkmagenta         
darkolivegreen      
darkorange          
darkorchid          
darkred             
darksalmon          
darkseagreen        
darkslateblue       
darkslategray       
darkturquoise       
darkviolet          
deeppink            
deepskyblue         
desktop             
dimgray             
dodgerblue          
firebrick           
floralwhite         
forestgreen         
fuchsia             
gainsboro           
ghostwhite          
gold                
goldenrod           
gradientactivecaption
gradientinactivecaption
gray                
graytext            
green               
greenyellow         
highlight           
highlighttext       
honeydew            
hotpink             
hottrack            
inactiveborder      
inactivecaption     
inactivecaptiontext 
indianred           
indigo              
info                
infotext            
ivory               
khaki               
lavender            
lavenderblush       
lawngreen           
lemonchiffon        
lightblue           
lightcoral          
lightcyan           
lightgoldenrodyellow
lightgray           
lightgreen          
lightpink           
lightsalmon         
lightseagreen       
lightskyblue        
lightslategray      
lightsteelblue      
lightyellow         
lime                
limegreen           
linen               
magenta             
maroon              
mediumaquamarine    
mediumblue          
mediumorchid        
mediumpurple        
mediumseagreen      
mediumslateblue     
mediumspringgreen   
mediumturquoise     
mediumvioletred     
menu                
menubar             
menuhighlight       
menutext            
midnightblue        
mintcream           
mistyrose           
moccasin            
navajowhite         
navy                
oldlace             
olive               
olivedrab           
orange              
orangered           
orchid              
palegoldenrod       
palegreen           
paleturquoise       
palevioletred       
papayawhip          
peachpuff           
peru                
pink                
plum                
powderblue          
purple              
red                 
rosybrown           
royalblue           
saddlebrown         
salmon              
sandybrown          
scrollbar           
seagreen            
seashell            
sienna              
silver              
skyblue             
slateblue           
slategray           
snow                
springgreen         
steelblue           
tan                 
teal                
thistle             
tomato              
transparent         
turquoise           
violet              
wheat               
white               
whitesmoke          
window              
windowframe         
windowtext          
yellow              
yellowgreen         

Example

Cover logo

We use the Enum.GetNames method and the typeof operator along with the Where extension method. With Where, we remove Control colors from the output. Other articles describe these methods in depth.

Enum.GetNameWhere

To compile the program, add the System.Drawing assembly to your project. When you execute it, all available colors will be printed to the Console. It uses the StartsWith method and LINQ extension methods.

StartsWithLINQ
C# program that generates HTML color table

using System;
using System.Drawing;
using System.Linq;

class Program
{
    static void Main()
    {
	// Get enum strings and order them by name.
	// Remove Control colors.
	foreach (string c in Enum.GetNames(typeof(KnownColor)).Where(
	    item => !item.StartsWith("Control")).OrderBy(item => item))
	{
	    // Write table row.
	    Console.WriteLine("<b style=background:{0}>{1}</b>",
		c.ToLower(),
		c.ToLower().PadRight(20));
	}
    }
}

Summary

This table contains the KnownColors from the System.Drawing namespace. Next we saw the console program that generates the table. A color sheet can be useful for selecting named colors for Internet articles.


C#: File: HTML