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

Pseudo Classes: Focus

I am in the video about Pseudo Classes. Instructor talked about Focus. Still not sure what exactly he means by that.

2 Answers

Hi Matthew Forsythe

:focus is used to style an element that is being targeted by a mouse or a keyboard.

See the below example:

p:focus {
  background: blue;
}

If you click on the p element its background will turn blue and it will remain blue unless you click anywhere on the browser.

Go ahead and play around with this.

Reggie Williams
STAFF
Reggie Williams
Treehouse Teacher

Matthew Forsythe Zaid is correct about targeting elements but it is mostly used for input elements where you are able to select these elements. Check out the first example here where the input turns yellow when it is selected because of the focus rule