Search code examples
htmlcssurlstyleshref

Is there a way to have URL-related CSS-Styles?


Is there a way to have URL-related CSS-Styles?

For example. I have a link on my webpage

<a href="#blue">Blue</a>

after clicking the URL changes to test.com#blue

Is it possible to apply style depending on this URL?

background-color: blue;

Solution

  • Only the :target pseudo-class which will match elements with an id that matches the fragment identifier in the URL.