Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS CSS Foundations Advanced Selectors Additional Pseudo-Classes

:target help

I don't understand what does the selector :target do! I've seen the video twice but don't get the idea behind.

1 Answer

Hugo Paz
Hugo Paz
15,622 Points

It affects all targets in a page. A target its a link to a specific part of the page. I'll give you an example:

<a href="#div1">target div 1</a>
<div id="div1">Something here</div> 
<div id="div2">Something here as well</div> 

if you click on the link target div 1, you go to that div in the page. You can see that in the video. Once he clicks on a link, the page scrolls to the corresponding div.

The :target selector then applies the css to that div which was targeted. If he had clicked on target section 2, the page would have scrolled to the specific page and the css would have been applied to that div and so forth.