XML technologies / CSS / CSS Cookbook / Forms / Highlighting input fields

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

Problem

The form input field currently used by the user should be visually highlighted.

Solution

Use the pseudo-class :focus. The following CSS rule changes the background colour of the currently used input element (see the following figure):

input:focus {
 background-color: yellow;
}

The selected input field’s background colour changes

Figure: The currently selected input field’s background colour changes.

Discussion

The following browsers support the pseudo-class :focus: Netscape Navigator 6+, Firefox, Safari and Opera 7. Browsers without support for :focus simply ignore the corresponding rules, ensuring backward compatibility.

See also

The recipe Styling textarea elements on styling textarea elements, and the table Overview of CSS properties for multiline input areas under Styling form elements.

  

 

 

 

back to top