Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS CSS Basics (2014) Basic Selectors Class Selectors

1 Answer

Brendan Whiting
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,696 Points

The id styles will overrule the class styles, because id's have higher specificity in CSS, but it isn't necessarily a bad idea to use both id's and classes together.

For example, you could have a class for all your buttons for certain default styles, and then an id for a specific button. Let's say I want all my buttons to have a certain padding and border radius, and they will default to be blue, but I'll overrule that for specific buttons:

.button {
  border-radius: 5px;
  background-color: lightblue;
  padding: 10px;

#cancel-button {
  background-color: red;
<button id="cancel-button" class="button">Cancel</button>

My cancel button will end up with the default properties from the button class (border radius, padding) but will have the red background color from it's id styles, not the default lightblue.