There are certainly other ways to achieve the same result so do check them out and give them a try. You can find the complete code on my GitHub repository.
#HEXADECIMAL COLOR CODE GENERATOR GENERATOR#
We've successfully built a random hex color generator using HTML, CSS and a few lines of JavaScript. If your icon set isnt black you can prepend brightness(0) saturate(100) to your.
Then the cycle repeats itself until the 6th round is over at which time a full 6-digit hex code will have been generated.Īll that's left is to set the textContent of the span tag and the background color of the page to be the value of hex.For this code to work well the starting color needs to be black.I can now access the hexValues array item in the position corresponding to the generated index number using bracket notation, then add it to the end of the hex variable i.e hex += hexValues. The random whole number generated is appended to a new variable index. This makes sure that any number generated is a valid hexValues index. It basically rounds it down to the nearest whole number. This page is part of The Hex Hub of The Color Spot at. So what do we do if we want a whole number larger than 1? We multiply it by the number we want (in this case, the length of the hexValues array) and wrap it within the Math.floor() function which returns the largest integer less than or equal to a given number. The chart below shows the hexadecimal color codes for shades of blue, teal, cyan, and similar colors.
Now, the Math.random() function picks a random number between 0 and 1 (not including 1) and returns a decimal but we don't want decimals.
New Android App Thousands of palettes in your pocket. Start the generator Explore trending palettes We are 3 million users iOS App Create, browse and save palettes on the go. Then it loops over the hexValues array 6 times and each time generates a random number using Math.random(). The super fast color palettes generator Create the perfect palette or get inspired by thousands of beautiful color schemes. Enter fullscreen mode Exit fullscreen modeĮvery time the button is clicked, the changeHex function is called which creates a variable hex and sets its value to #.