Difference between :focus and :active selector in HTML


:focus selector is used to applying a required style when a form element got to focus like button, link, input box. An element can get focus using mouse or using tab key. A focus remains on the element until another element gets focus.


:active selector is used to indicating that an anchor tag is active or a button is active. When the mouse is down, active selector applies and remains applied till the mouse is down.


Following the example, shows usage of :focus as well as :active selector on button and link.

<!DOCTYPE html>
   <title>Selector Example</title>
      button {
         border: 2px solid black;
      button:focus {
         border: 2px dotted red;
      a {
         color: black;
      a:active {
         color: red;
   <button type="submit">Focus Me</button>
   <a href="#">Active Me</a>