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 How to Make a Website Styling Web Pages and Navigation Build Navigation with Unordered Lists

Yariv Steinberg
Yariv Steinberg
1,788 Points

What's the difference between: gallery { x:y; } and #gallery { x:y; } ?

.

2 Answers

Ryan Field
PLUS
Ryan Field
Courses Plus Student 21,242 Points

Hi, Yariv. In CSS, a hash (#) indicates that you want to style an element with a particular ID. Similarly, a period (.) indicates a class, while a colon (:) represents pseudo elements and selectors. Items without any prefixing punctuation mean that you want to target elements themselves, such as div or p. These must be actual elements used for HTML markup, and since there is no gallery element, you cannot use simply gallery in your CSS; you must use either .gallery or #gallery.

Hi Yariv,

Your first selector example would be invalid because it would be looking for an html element named "gallery" and there is no element with that name.

It's looking for something like this:

<gallery></gallery>  <!-- This is invalid html -->

In your second example the selector is looking for an element with an id attribute of "gallery"

An example from this project:

<ul id="gallery">
</ul>

Since the ul has an id attribute of "gallery" the selector #gallery will match that element.

id selectors are always prefixed with # followed by the id and class selectors are always prefixed with . followed by the class name. Element selectors are just the name like p, or h1