What's so bad about in-line CSS?

Posted by ChessWhiz on Stack Overflow See other posts from Stack Overflow or by ChessWhiz
Published on 2010-04-10T06:22:13Z Indexed on 2010/04/10 6:23 UTC
Read the original article Hit count: 327

Filed under:
|
|

When I see website starter code and examples, the CSS is always in a separate file, named something like "main.css", "default.css", or "Site.css". However, when I'm coding up a page, I'm often tempted to throw the CSS in-line with a DOM element, such as by setting "float: right" on an image. I get the feeling that this is "bad coding", since it's so rarely done in examples.

I understand that if the style will be applied to multiple objects, it's wise to follow "Don't Repeat Yourself" (DRY) and assign it to a CSS class to be referenced by each element. However, if I won't be repeating the CSS on another element, why not in-line the CSS as I write the HTML?

The question: Is using in-line CSS considered bad, even if it will only be used on that element? If so, why?

Example (is this bad?):

<img src="myimage.gif" style="float:right" />

© Stack Overflow or respective owner

Related posts about css

Related posts about subjective