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 Basics (2014) Basic Selectors Reusing Classes

Virginia Ceban
Virginia Ceban
1,510 Points

what will happen if an element have 2 classes and they have the same properties, what then overrides?

I saw that if an element have a class and a id, and in there is the same property, the id property overrides the class... but what happen if an element have 2 classes and they have the same properties, what then overrides?

J S
J S
7,387 Points

Hey Virginia,

I believe it's whatever class is declared last in your CSS will take precedence. For example, in my code snippet below, the style in the "second" class will override "first" (no matter what order you put them in the HTML).

.first { background-color: red; }
.second { background-color: green; }

2 Answers

Stephanie van Doleweerd
Stephanie van Doleweerd
3,075 Points

Just to be pedantic; this is because CSS stands for "cascading" style sheet - the instructions cascade from the top of the CSS file to the bottom, and the instructions at the bottom of the cascade will take priority.