The source code of a file should contain one language. Probably always, but after parsing the file is difficult enough for the most of us. All scripting and styling should be placed extern. The current specification (and future) does allow inline scripting and styling, but that's not a reason to use it.
First of all: It breaks backwards compatibility. I'm talking about a XML document (like XHTML 1.0 Strict or Transitional), 'cause this doesn't count for an HTML document. Although it validates if you use XML comments within your style
or script
element you shouldn't use it! Try serving you XHTML as XML (application/xhtml+xml
) and you know what I mean. Nothing is applied then ;), you get an unstyled non scripted version of you site. Is that what you want?
If you only use one child selector or an ampersand in JavaScript you are getting problems with XML, which doesn't allow these. Off course you could use <![CDATA[ ]]>
, but that break backwards compatibility even more. And why would you do that, if it's that easy to place it in an external file? JavaScript's (I hope you don't use VBScript) can be placed external like this:
<script src="file.js" type="text/javascript"></script>
CSS is also really easy and you can even do tricks if you have multiple CSS files. CSS can be placed external like this:
<link rel="stylesheet" href="file.css" type="test/css" />
Probably you are still authoring in HTML. It can still have a lot of advantages taking your style sheets and scripts extern. Those files can be cached, it's easier to update and maintain your site. You have a bigger future compatibility. You should try (and that's really easy) never to use the style
attribute, although it stays in XHTML 2.0 it's really not necessary to use this attribute. The only good argument for it comes from Eric Meyer: The
(He didn't said this literally).
style
attribute can be used to keep the intended style from the original author.
There is even a separate working draft for that style
attribute. The authors are looking of it will be possible to allow selectors within that little attribute, remember what I said about the child selector... If it was up to me (and a lot of people are happy that that isn't true) I would remove the style
and script
element. Remove the style
attribute and have something like this (Bas Hamar asked me sometime if this was already possible and I still like that idea, anyone who wants to take it to the working group?):
<link rel="stylesheet" type="text/css" href="file.css" /> <link rel="script" type="text/javascript" href="file.js" />
I know the style
element is most of the time (with experienced authors) used to hide styles from Netscape Navigator 4.x. You probably know, but maybe you have never thought of it, but the @import
rule (which is used inside the style
element) could (should) be used inside a style sheet. That way you could separate positioning from layout for example. Or colors from fonts, whatever you like ;) using multiple @imports. You style sheets are hidden from Netscape Navigator 4.x and you can maintain them much easier, what do you want more?