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 Selectors Selectors - Beyond the Basics Course Overview

Attribute selectors

when are attribute selectors important? because i can simply choose to use the class and ids instead of calling the properties too?

1 Answer

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

There's a lot to learn about attribute selectors. I realise that ID selectors are very specific to a particular element but attribute selectors can offer you even more styling control.

For example, you can style an element of a specific attribute that has a specific value.

Let's say that you wanted to style links that always open in a new browser tab.

You do that with the target attribute of the anchor element.

a[target="_blank"] {
  background-color: red;
  padding: 5px;
}

Now, you can use any style you deem appropriate to let users know when they're opening links that will open a new tab.

Here's a link where you can read more about attribute selectors.

https://www.w3schools.com/css/css_attribute_selectors.asp

W