UPDATE! I'm moving this site to: www.emirplicanic.com.

BeWebmaster

Create Web Safe Color palette using JavaScript

Ad

Generating web safe color palette can be easily done using JavaScript. Web safe palette contains 256 colors that we can come up with by mixing some basic colors.

Here is the code.

<script language="javascript">

//first lets start with the table that will contain the palette
t='<table width="50%">';

//next we define the array of basic colors including black, white and gray
c=new Array('00','CC','33','66','99','FF');

//now we will iterate through colors. Notice how number 6 corresponds to number of items in the array c
for(i=0;i<6;i++){
 for(j=0;j<6;j++){

 // each row will have 6 colors
  t +='<tr>';
   for(k=0;k<6;k++){

    //this creates hex code for each color
    l=c[i]+c[j]+c[k];

    //now lets create table cell for each color
    t+='<td bgcolor=#'+l+'>#'+l+'</td>';
   }
  t +='</tr>';
 }
}

//now let's display the palette 
document.write(t+'</table>');
</script>

See the result below