{"id":4056,"date":"2017-02-20T04:13:18","date_gmt":"2017-02-20T09:13:18","guid":{"rendered":"http:\/\/local.brightwhiz\/?p=4056"},"modified":"2021-12-08T13:20:05","modified_gmt":"2021-12-08T18:20:05","slug":"html-color-names-major-browsers","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/html-color-names-major-browsers\/","title":{"rendered":"The HTML Color Names you can use in all Major Browsers"},"content":{"rendered":"\n
Web design has evolved over the decades and certainly along the way has been the introduction of the use of HTML color names. This is a friendly way of defining colors on HTML<\/a> elements using names rather than the Hex color codes.<\/p>\n\n\n\n The challenge with these is that you may not know what colors are valid for use in your project as these cannot just be any color you can perceive.<\/p>\n\n\n\n There are actually currently 140 HTML color names you can pick from<\/a> and they are used just the same way you would use the Hex codes in either HTML, CSS<\/a>, or JavaScript<\/a> or whichever way will work for you.<\/p>\n\n\n\n You can use your HTML Color attributes names directly in your HTML as shown in this example but as of HTML5 the color attributes are no longer supported so take note. These have been added for backward compatibility.<\/p>\n\n\n\n It is recommended to use the style attribute to set your colors in HTML as this example shows.<\/p>\n\n\n\n The same color names can be used in your CSS files by setting the properties as seen in this example:<\/p>\n\n\n\n There are several ways you can do the same in JavaScript. Because of the dynamic nature of the language you have several ways to code it in. Generally, this would be a way to set the color of an element using JavaScript:<\/p>\n\n\n\nHow to use HTML Color Names on Your Website<\/h2>\n\n\n\n
<body>\n \n <p color="#ff0000">Old style Red paragraph<\/p> \n \n <p color="red">Old style Red paragraph using color names<\/p> \n \n<\/body><\/code><\/pre>\n\n\n\n
<body>\n \n <p style="color:#ff0000;">Old style Red paragraph<\/p> \n \n <p style="color:red;">Old style Red paragraph using color names<\/p> \n \n<\/body><\/code><\/pre>\n\n\n\n
How About in CSS?<\/h2>\n\n\n\n
p{\n color:red;\n}<\/code><\/pre>\n\n\n\n
How About JavaScript Styling?<\/h2>\n\n\n\n
document.getElementById("redText").style.color = "red";<\/code><\/pre>\n\n\n\n