Active class is not limited to links. You can add it to any element of your choice. You can specify your styles and add them to an element when you think it is considered to be active.
Each element has classList property and this property points to an object that has 2 methods add() and remove(). The add() method is used to add a class to the element and the remove() method is used to remove a class from the element.
In the following example, we have 5 buttons and when we click any of the buttons, we will simply add an active class to it. As a result, the background of the button will be changed to green color. Please have a look over the code example and the steps given below.
HTML & CSS
We have 2 elements in the HTML file (div and button). The div element with a class of container is just a wrapper for the rest of the elements.
We have done some basic styling using CSS and added the link to our style.css stylesheet inside the head element.