CSS focus Selector (:focus)
What is CSS :focus Selector?
CSS :focus selector occur when user perform mouse click action inside element.
Syntax
General syntax of CSS :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.
<!DOCTYPE html>
<html>
<head>
<title>CSS :focus Selector</title>
<style type="text/css">
input:focus {
background-color: yellow;
}
</style>
</head>
<body>
<input type="text" name="username" placeholder="Username" />
</body>
</html>
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.