Share this page 

Nice "focus" effect in a FORM fieldTag(s): Form

In CSS, the :focus pseudo-class can be used to apply styles to a page element that receives focus.

IE doesn't recognise this at all, you need add the style "manually".

In this HowTo, the special javascript function to init the style is called (from the BODY onLoad) only if the browser is IE.

  function initie() {
    // called from the BODY onLoad with IE only.
    // for mozilla-based browser only the CSS is used.
    var i = 0;
    // get all the forms
    var f = document.forms[i];
    while (f) {
       // get all elements of the current form
       var elem = document.forms[i].elements;
       for (var i = 0; i < elem.length; i++) {
           // make a reference to our style
           elem[i].onfocus = function() {
                   this.className += ' focusie';
           elem[i].onblur = function() {
                   this.className = this.className.replace('focusie', '');
       // next form if any
       f = document.forms[++i];
/* mozilla */ 
input:focus, textarea:focus  {
background-color: lightblue;

/* ie */
input.focusie, textarea.focusie {
background-color: lightblue;


<!--[if IE]>
<body onload="initie();">
<!--[if !IE]> <-->
<!--> <![endif]-->

<form name='test'>
<LABEL FOR="tf1">Name </LABEL><br>
<input id="tf1" type="text" size="40">
<LABEL FOR="tf2">Email </LABEL><br>
<input id="tf2" type="text" size="40">
<LABEL FOR="tf3">Comments </LABEL><br>
<textarea id="tf3" rows="5" name="comments" cols="45" wrap="virtual"></textarea></p>

<p><input type="submit" value="Submit"></p>


Try it here :