Export (0) Print
Expand All
0 out of 3 rated this helpful - Rate this topic

:focus pseudo-class

Sets the style of an element when it gains focus.

CSS 2.1, Section 5.11.3Internet Explorer 8

Syntax

selector :focus {...}

Parameters

selector

A CSS simple selector

Standards information

Remarks

In an HTML document, an element must receive focus from the user in order to become active and perform its tasks. For example, users must set input focus on a link in order to follow it. Similarly, users must give a TEXTAREA focus in order to enter text into it.

There are several ways to give focus to an element:

  • Designate the element with a pointing device. Even elements that do not typically accept input, such as div and body elements, receive focus when clicked with the mouse.
  • Navigate through the document with the TAB and Shift+TAB keys. The document's author may define a tabbing order that specifies the order in which elements will receive focus.
  • Select an element through a keyboard shortcut.

This pseudo-class requires that Windows Internet Explorer be in IE8 Standards mode rendering. For more information, see Defining Document Compatibility.

Examples

The following style rule will change the background color of any element that receives input focus:


*:focus {
    background-color: #ffc;
} 

 

 

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.