How to use :target Selector


#1

I’m having trouble using :target Selector with an #id.

:target {
    color: #e5eecc;
}
    
    <a href="#news1"></a>   

    <p id="news1"><b>New content 1...</b></p>

When I click on the link, the 404 error page opens, how can I do this without receiving this error?


#2

Add class external to link

<a href="#news1" class="external"></a>

#3

I tried to use the “external” class, but when I click, the page comes back, as if it had put the class “back” :frowning:

Thank you!

#section1:target {
  color: red;
}

<a href="#section1" class="external">Change Color</a>
 

<h1 id="section1">Section 1</h1>