CSS Tutorial

CSS Style

CSS Layout Style

CSS Float Style

CSS Reference

CSS focus Selector (:focus)


What is :focus Selector?

CSS :focus selector occur when user perform mouse click action inside element.

Browser Compatibility

  • Google Chrome 2+
  • Mozilla Firefox 1+
  • Internet Explorer 8+
  • Opera 7+
  • Safari 1.3+

Note: Here details of browser compatibility with version number may be this is bug and not supported. But recommended to always use latest Web browser.

Syntax

General syntax of :focus selector,

:focus {
	property: value;
	property: value;
	...
}

input:focus {
	property: value;
	property: value;
	...
}

Example:

CSS :focus selector occur when user perform mouse click action perform inside element.

<style type="text/css">
    input:focus{
        background-color: yellow;
    }
</style>
</head>
<body>
    <input type="text" name="username" placeholder="Username" />
</body>

Run it...   »

Example Result: