rhgiant — 2011-07-23T02:52:11-04:00 — #1
Would both be correct, or is one better than the other?
<meta charset="utf-8" />
ralphm — 2011-07-23T03:13:15-04:00 — #2
The first one is the standard for HTML5, used like so:
The second would be used for XHTML5:
<meta charset="UTF-8" />
rhgiant — 2011-07-23T03:26:03-04:00 — #3
Would it be ok to close it in standard html5?
ralphm — 2011-07-23T03:30:54-04:00 — #4
No, I don't think so. The closing slash like that always was invalid HTML—but something the browsers have tolerated.
xhtmlcoder — 2011-07-23T05:24:43-04:00 — #5
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.
rhgiant — 2011-07-23T07:33:50-04:00 — #6
Is it the same for <link rel=...>?
gar_onn — 2011-07-23T10:13:54-04:00 — #7
you can omit the trailing slash from all elements that have no content
c_ankerstjerne — 2011-07-23T12:39:49-04:00 — #8
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.
rhgiant — 2011-07-23T12:39:54-04:00 — #9
My question was rather: can I add it (in html5)?
oddz — 2011-07-23T14:50:21-04:00 — #10
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.
stomme_poes — 2011-07-23T17:33:53-04:00 — #11
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.
felgall — 2011-07-23T18:47:37-04:00 — #12
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).
system — 2011-07-23T22:36:59-04:00 — #13
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.
c_ankerstjerne — 2011-07-24T05:03:09-04:00 — #14
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 >?
system — 2011-07-24T05:26:55-04:00 — #15
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.
xhtmlcoder — 2011-07-24T05:31:14-04:00 — #16
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.
ralphm — 2011-07-24T06:23:33-04:00 — #17
I still can't get out of my head that /> is invalid HTML.
afam4eva — 2011-07-24T06:32:53-04:00 — #18
You can use either. If it's a tag without a content then the tag is ideal.
system — 2011-07-24T06:48:53-04:00 — #19
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.
rhgiant — 2011-07-24T07:23:05-04:00 — #20
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 →