JSFiddle - React, Tailwind, and code Playground by Graham Fairweather May 18, 2013 HTML <form id="TheForm"> <input id="color" type="text" /> <br/> <input id="submitColor" value="Submit" type="button" /> </form> <span id="coltext">This text should have the same color as you put in the text box</span> CSS #TheForm { margin-left: 396px; } #submitColor { margin-left: 48px; margin-top: 5px; } JavaScript function changeBackground() { var color = document.getElementById("color").value.trim(), rxValidHex = /^#(?:[0-9a-f]{3}){1,2}$/i; if (rxValidHex.test(color)) { document.getElementById("coltext").style.color = color; } else { alert("Invalid CSS Hex Color"); } } document.getElementById("submitColor").addEventListener("click", changeBackground, false);