I\'m trying to style my element with pseudo-class and pseudo-element. like hover::before
is working perfectly but :visited::before
is not working.
It may be possible, but don't take it for granted. According to the spec,
Note: It is possible for style sheet authors to abuse the :link and :visited pseudo-classes to determine which sites a user has visited without the user's consent.
UAs may therefore treat all links as unvisited links, or implement other measures to preserve the user's privacy while rendering visited and unvisited links differently.
Inserting content can change the size of the element, so it would be trivial to detect this and know if the user has visited some sites. Therefore, most browsers won't allow you to do so.