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

HTML

Contradictions

So originally, I had started out with Codecademy since it was free. I started off with web fundamentals but it felt as if Codecademy was missing something so I signed up for Treehouse. I'm doing to HTML & CSS Learning Adventure. Now that I'm learning to create a new website, I see that Treehouse teaches us to use style in backround like...

< style > body { background-color: red; } < /style >

in Codecademy, it is taught with < body style="background-color: red;" >

Obviously since I'm sticking with Treehouse then I should use their preferred method, but are they the same? Is one easier than the other? Or is one of them just overkill?

Codecademy does this before they teach you CSS in their HTML learning tree. Once they teach you CSS they don't use inline styles anymore.

Daniel Berryhill
Daniel Berryhill
16,952 Points

Richard is correct. Codecademy starts with inline styles before showing you how to link to external stylesheets.

Codecademy is great at teaching you the syntactic structure of languages, but not so great at telling you when and why to use certain practices. This is where Treehouse really shines.

So I should stick to the methods that Treehouse teaches me?

Daniel Berryhill
Daniel Berryhill
16,952 Points

Sure, Treehouse teaches solid practices. More importantly, they try to convey how to make important design decisions.

(I'm not trying to dump on Codecademy though. They're great in their own way. They just don't cover as much material or go into as much detail.)

Chase Lee
Chase Lee
29,275 Points

Yes if those are the things that Treehouse and Codecademy teach. Then stick to Treehouse.

4 Answers

Dan Ridley
PLUS
Dan Ridley
Courses Plus Student 14,839 Points

Are you referring to external style sheets compared to inline styles?

Patrick Cooney
Patrick Cooney
12,216 Points

I'm not really clear on the first example, but it looks like it is another form of inline? You shouldn't use either. It is considered best practice to have all your styles in an external stylesheet. You should do your best to completely separate style from content. The one situation I can think of off the top of my head where this doesn't apply is when you're adding styles to individual elements inserted in a CMS.

edit: code won't display correctly. Put a red class in your main css file, link it to your html page and assign the class using class= instead of style=.

Chase Lee
Chase Lee
29,275 Points

I think the first one is internal because of the style tags.

Patrick Cooney
Patrick Cooney
12,216 Points

Ooooooooooooh, ok. External style sheets have been considered best practice for years and years so I'm not totally familiar with style tags.

Chase Lee
Chase Lee
29,275 Points

There are three ways to style you HTML using CSS.

  1. External stylesheets, (which is what Treehouse uses). This is most preferable because you can effect multiple HTML page and tags at once using only one declaration.

2.Internal styles, (which is what you posted that Treehouse uses but is inncorrect). This is next on the list because you can effect multiple elements in one declaration but if you want to do the same styles on another sheet you have to copy the code and put it on that one.

3.Inline styles, (which is what Codecademy uses). This is last one the list because it is the least preferable. The reason is because for every tag you want to style you have to give it its own declaration. You cannot use one declaration across multiple sheets or elements.

So inclusion you should always use external as the are the easiest to use and the most compatible for other programers.

Nathan F.
Nathan F.
30,773 Points

Inline styles have another disadvantage, as I recall, in that they are also considered more important in the cascade than external styles. So styling HTML markup with inline styles, then trying to later style those elements with external stylesheets, will only lead to frustration and madness.

Chase Lee
Chase Lee
29,275 Points

Yes. I forgot to put that in there. External styles are at the bottom of importance then internal and finally inline.

Kevin Korte
Kevin Korte
28,148 Points

Yep, about the only time you want to use inline styles is to let the CSS value be set on the fly by the language of your choice.