ometimes, deciding on a color scheme for a site is more of a problem than is implementing it. I’ve sat on committees intended to design Web sites by consensus and I can tell you from experience: Getting more than two people to settle on a color scheme is no easy task! A little programming helps though. You can simplify color scheme selection by letting people see how their color preferences interact on-screen.
Although displaying a Web-safe color palette is relatively easy, simply displaying the colors doesn’t give users an easy way to see how selected colors interact with each other. How can you get people to choose and agree on sensible colors for a site?
Make the Web-safe color display interactive, using JavaScript to apply selected colors to some sample content and let users see immediately how their chosen colors look together. Figure 1 shows how the completed application looks.
![]() |
Create a Web-safe Palette This solution has two goals?displaying the Web-safe palette and making it interactive. Displaying the palette is easy; you use some nested loops and a simple array to build a table whose cells each represent a different entry in the palette. A pair of radio buttons on the page lets users choose whether they’re selecting a foreground or a background color. Finally, to make the display interactive, you can connect the onClick event for each colored cell in the table to a function that applies the selected color to either the foreground or background color of a separate display?based on the currently selected radio button. Simple event handlers for the radio buttons maintain the foreground/background value, and a “dummy” tag holds content so users can see the effect of their chosen colors immediately.
To get started, open up your favorite text editor and add the following code:
The CSS Rules shown above position elements on the page. Next, create three tags to hold the color table, the radio button controls, and a test area where the color effects appear. Because each of the
cells will be clickable, the td rule turns the standard cursor into the hand cursor when users move the mouse over a table cell. Note that the rules don’t specify any colors?users will determine the colors in the testArea by clicking on the cells in the palette.
| Add the following between the tags:
The colorTable ‘s content will be generated by a function called createTable(). Also note that the controls
possesses two radio buttons?one to set the foreground color and one to set the background color. Each radio button has an onClick event that sets the value of a flag?colorToSet?in the script to either “fore” or “back”. The function that displays the selected colors in the testArea
will check this flag to see which property to change. The controls
also contains labels that display the current color values of the foreground and background properties of the testArea. Initially, these values are set to black text (#000000) on a white (#ffffff) background. Finally, the testArea
contains some placeholder text so users can see how the colors interact.
Make the Palette Interactive
The preceding code creates a table by using three nested for loops. The colors array holds the hexadecimal color values acceptable for each of the red, green, and blue components of a Web-safe color palette. The code then uses the nested loops to iterate through each of the values. The i loop represents the red component, the j loop represents the green component, and the k loop represents the blue component of the color to be displayed. By including the HTML table markup tags and looping through the acceptable values of the Web-safe palette stored in the colors array, the createTable() function creates a table with 6 colors and 36 rows?the 216 colors of the Web-safe color palette. You may have noticed that as the code constructs the tags, it also adds an onClick event handler that points to a function called setColor(). The setColor() function takes the
| element itself as an argument (the "this" argument). You'll need to add the setColor() function?and the colorToSetFlag mentioned earlier to the page. Add the following to the script:
|
When the page first loads, the colorToTest flag is set to 'fore', but the flag value changes from 'fore' to 'back' as users change the selected radio button. The setColor() function uses DOM properties to access the text stored in the element passed to the function. It then uses that text (the color value) to apply the selected color to either the foreground or background of the testArea
| depending on the current colorToSet flag value. Finally, the setColor() function sets the innerHTML property of either the foreground or background labels to the selected color value.
That's all there is to it! You can use this Web-safe color palette application to help select a color scheme for anything from a single element to an entire site. You could easily extend the application to let users change the font, weight, and size of the text in the test area. In fact, the closer you make the content of the test area to the actual content of the intended site, the more likely it is that the process of selecting a color scheme will go smoothly.
Share the Post:
![]() ![]() The Best Mechanical Keyboards For Programmers: Where To Find Them
May 29, 2023
When it comes to programming, a good mechanical keyboard can make all the difference. Naturally, you would want one of the best mechanical keyboards for programmers. But with so many ![]() ![]() The Digital Panopticon: Is Big Brother Always Watching Us Online?
May 26, 2023
In the age of digital transformation, the internet has become a ubiquitous part of our lives. From socializing, shopping, and learning to more sensitive activities such as banking and healthcare, ![]() ![]() Embracing Change: How AI Is Revolutionizing the Developer’s Role
May 25, 2023
The world of software development is changing drastically with the introduction of Artificial Intelligence and Machine Learning technologies. In the past, software developers were in charge of the entire development ![]() ![]() The Benefits of Using XDR Solutions
May 24, 2023
Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved ![]() ![]() How AI is Revolutionizing Fraud Detection
May 23, 2023
Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across ![]() ![]() Companies Leading AI Innovation in 2023
May 22, 2023
Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several ![]() ![]() Step-by-Step Guide to Properly Copyright Your Website
May 18, 2023
Creating a website is not easy, but protecting your website is equally important. Implementing copyright laws ensures that the substance of your website remains secure and sheltered. Copyrighting your website ![]() ![]() Fivetran Pricing Explained
May 17, 2023
One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of ![]() ![]() Kubernetes Logging: What You Need to Know
May 16, 2023
Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes ![]() ![]() Why Is Ransomware Such a Major Threat?
May 15, 2023
One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing ![]() ![]() Tools You Need to Make a Data Dictionary
May 12, 2023
Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as ![]() ![]() 10 Software Development Tips to Get Early Funding for your Startup
May 11, 2023
If you’re thinking about a startup, it’s likely you need to raise an initial round of funding for your venture. This article covers some of the very early development techniques |