HTML & CSS
Would both be correct, or is one better than the other?
<meta charset="utf-8" />
The first one is the standard for HTML5, used like so:
The second would be used for XHTML5:
<meta charset="UTF-8" />
Would it be ok to close it in standard html5?
No, I don't think so. The closing slash like that always was invalid HTML—but something the browsers have tolerated.
HTML5 is like a complete slut; it allows both methods it swings both ways so you could use either for 'text/html' version (obviously the first version being more correct). Though obviously you need the closing slash version for XHTML5 to conform within well-formedness constraints.
So yes actually BOTH methods can be used in the HTML version! Whereas only version two is allowed for the XHTML version.
Is it the same for <link rel=...>?
you can omit the trailing slash from all elements that have no content
Are you sure abuot this? It is my understanding that this is simply because browsers generally doesn't understand null end tags (as in HTML 4.01 and below), not because it's actually valid.
My question was rather: can I add it (in html5)?
It is correct, the new book by Sitepoint on HTML5 covers this and other "forgiving" aspects in comparison to HTML4. Though I will be leaving out the trailing slash for the time being with HTML5. Mainly because I write HTML4, validate against it then swap the doctype, but thats another story.
You can either use a trailing slash or omit it. Good practice though is to omit it when writing HTML5 just as you were writing HTML4.
Would it be ok to close it in standard html5?
Who knows, maybe some day the Web Standards Evangelical Army's black-clad jack-booted storm troopers will come into your bedroom in the night-time and stuff you in a sack and drag you away for closing EMPTY elements in "standard" HTML5. But I doubt it. No browser cares, that's for sure.
The space in front of the slash is unnecessary unless you still need to support Netscape 4.
I would recommend leaving out the slash unless you intend to start serving the page as XHTML as soon as IE8 use falls low enough to ignore (since IE8 and earlier don't support XHTML).
I actually prefer the space just for ease of reading. Makes the code clearer to me.
But then I'll often format really long tags as attribute per line indented with the /> on it's own line for clarity. Beats the ever living tar out of the hard to read run-on lines you see in a lot of code.
one of the reasons I prefer XHTML formatting in the first place... with just > you're never sure if it's the end of a tag or the start of one.. with /> it's always clear.
with just > you're never sure if it's the end of a tag or the start of one.. with /> it's always clear.
When would a tag ever start with a >?
Methinks you failed to grasp what I was saying. there are two types of tags, those that have content, and those that do not... when I say tag I'm referring to the entire element -- the opening and closing of the tag with it's content; basically in the DOM sense of it.
> means this is a starting tag. </label> would be the end of the tag.
/> is the close of the tag.
If I've scrolled to where I can't see the opening, using HTML 4 I don't know what tag it is so I can't be sure if it's an opening tag or a self-closing. Always using /> means I can always make that determination even if /> is all I can see... saving me the bother of scrolling up to find out.
A common formatting method if you practice the 76 rule -- which is why real programming languages that have a block structure are CONSISTENT in it's application. Something HTML is a miserable failure at and really the only thing XHTML gives us that's an improvement.
Yes, for the new void elements it is the case. Obviously you cannot do something like: <p /> or <br></br> for Fred 'text/html'.
We digress as we are only looking at the META or other VOID elements only for this thread. Like I said it is "bad practice" for the 'text/html' version but legal.
For you reading pleasure: http://www.w3.org/TR/html-markup/syntax.html#syntax-elements
I believe that SP Book has some outstanding errata waiting regarding certain wording upon p54.
I still can't get out of my head that /> is invalid HTML.
You can use either. If it's a tag without a content then the tag is ideal.
While for me, HTML's "formatting rules" (aka WHAT RULES!?!) are so loose, permissive and idiotic that I could give a flying purple fish what it considers valid or invalid... Hence why I like XHTML as it has more consistent rules... and thing HTML5's "just slap together anything" is so much of a colossal step in reverse.
Rules are good. They tend to keep you out of trouble in the first place -- as opposed to just sleazing stuff together any old way... which ever since HTML 3 seems to be 'the norm'. Again, see all the people STILL vomiting up HTML 3.2 and slapping a 4 tranny or 5 lip-service on it.
Why would <meta... /> and <link rel... /> be "bad practice" when <img... /> isn't?
Btw, is <link rel... /> to be considered like <meta> in terms of bad practice/self-closing-ness?
next page →