Is it possible to define custom colors in html and use them in a css

Posted on 2011-03-03
Last Modified: 2012-05-11
I want to define a custom color and use it in my css
such as


where myhighlightcolor can be a color which I choose.Is it possible to do this in html or css ?If yes, then where do i define the color?

Question by:res_this
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 35029039
You should do this with Javascript or PHP.

Expert Comment

ID: 35029141
I would use javascript for changing the class
more on this

if you spend sometimes with jQuery framework - it will be a lot easier in the future

Expert Comment

ID: 35029554
You've pretty much answered your own question, in your stylesheet define:
    background:#ffcc00;/*or your own color*/

Then set the class of the tag that surrounds the text to be highlighted for example:
<span class="highlightedtext">blah blah</span>

No need to resort to PHP or JavaScript

LVL 83

Accepted Solution

Dave Baldwin earned 500 total points
ID: 35029903
If you are wanting 'myhighlightcolor' to be a variable that you can change in one place and use in many, then you will need to use a programming language like Javascript, ASP, or PHP.  HTML and CSS are 'description' languages but not programming languages but you can use programming languages to alter the HTML and CSS that is generated.

Author Closing Comment

ID: 37503775
not clear

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
migrating to phpbb forum from vBulletin 4.2 3 97
How do I Enable submit button only if listbox has items 4 65
title attribute 5 33
Scroll 5 news at a time using vticker 2 41
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question