Jump to content

Closing Brackets


knystrom18

Recommended Posts

Hey,I've seen both methods of closing tags without actually closing them.Ex:

<meta name='keywords' content='blah blah blah blah blah'>VS<meta name='keywords' content='blah blah blah blah blah' />

Same thing with images:

<img src='coolpic.jpg'>VS<img src='coolpic.jpg' />

Should any element that does not specifically have a closing tag be closed with a ">" character or "/>" characters?Thanks,- K

Link to comment
Share on other sites

do you know what doctype you are validating to?/> is for XHTML, for those tags that could be considered empty, like <img> or <br>(if you validate your pages you'll find out which ones need what)http://www.w3schools.com/xhtml/xhtml_howto.asp

Link to comment
Share on other sites

Cool, thanks.Doctype I'm currently using:

<!DOCTYPE html>

I was just looking at this actually, and was wondering if I should be using either of these instead:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

I'll be using XHTML in the site.

Link to comment
Share on other sites

I see, so you're using HTML5. Well, HTML5 doesn't have a lot of full range support yet, at least not for the entire spec, as it is not yet completed. in the meantime the choice comes down to HTML or XHTML. XHTML is more those who plan on using XML within their documents, although I prefer to use it anyway because it requires a bit stricter and cleaner markup. Which ever one you choose, use Strict. And validate your pages often so you can catch mistakes as you go along. (if you use FF and have web developers toolbar, there is a display validation option so you can see errors as they appear).

Link to comment
Share on other sites

Ok, will do. I'ma use XHTML for the same reasons you do.Thanks for your help.I had no idea the Web Development Toolbar had that capability... That's pretty slick. I'm assuming that option is under tools, and once clicked, it stays active until you click it again?Wait... if I use the XHTML 1.0 doctype, do I need to/should I get rid of the HTML 5 tags?

Link to comment
Share on other sites

I'm not sure, since I haven't started toying around with HTML5. See what the validator says. Most likely HTML5 tags will not work in a document validating to a different doctype (not supporting those features).

Link to comment
Share on other sites

<!DOCTYPE html>

is the HTML 5 DOCTYPE. There is no XHTML 5 though (yet).

Link to comment
Share on other sites

<!DOCTYPE html>

is the HTML 5 DOCTYPE. There is no XHTML 5 though (yet).

The HTML 5 DOCTYPE allows for XHTML code as well. HTML5 serialised as XHTML is called XHTML 5, so developers can choose. But you need an <?xml ?> declaration preceding the DOCTYPE line, if I remember correctly.
Link to comment
Share on other sites

The HTML 5 DOCTYPE allows for XHTML code as well. HTML5 serialised as XHTML is called XHTML 5, so developers can choose. But you need an <?xml ?> declaration preceding the DOCTYPE line, if I remember correctly.
so if one where to use <!DOCTYPE html>, they would be able to use XHTML syntax within the document, have it validate and pass? (taking into consideration the XML declaration you mentioned)
Link to comment
Share on other sites

so if one where to use <!DOCTYPE html>, they would be able to use XHTML syntax within the document, have it validate and pass? (taking into consideration the XML declaration you mentioned)
Yes, I'm quite sure of that. I've looked at the specification.
Link to comment
Share on other sites

The XML declaration must include the version:

<?xml version="1.0"?><!DOCTYPE html>

Link to comment
Share on other sites

Guest FirefoxRocks

Actually, if you want to use the XML serialization of the HTML 5 spec, no DOCTYPE is required usually.

What will the DOCTYPE be?In HTML:<!DOCTYPE html>In XHTML: no DOCTYPE is required and its use is generally unnecessary. However, you may use one if you want (see the following question). Note that the above is well-formed XML and so it may also appear in XHTML documents.
Under what conditions should a DOCTYPE be used in XHTML?Generally, the use of a DOCTYPE in XHTML is unnecessary. However, there are cases where inclusion of a DOCTYPE is a reasonable thing to do: 1. The document is intended to be a polyglot document that may be served as both HTML or XHTML. 2. You wish to declare entity references for use within the document. Note that most browsers only read the internal subset and do not retrieve external entities. (This is not compatible with HTML, and thus not suitable for polyglot documents.) 3. You wish to use a custom DTD for DTD-based validation. But take note of what's wrong with DTDs.
Link to comment
Share on other sites

The XML declaration must include the version:
<?xml version="1.0"?><!DOCTYPE html>

FYII put that in and get a validation error:
Saw <?. Probable cause: Attempt to use an XML processing instruction in HTML. (XML processing instructions are not supported in HTML.)
Admittedly, being able to use HTML 5 tags in an XHTML 1 document would be awesome, but I've decided to take the easier road and validate to XHTML 1 instead of using more code than is absolutely necessary to validate to an (X)HTML 5 document.
Link to comment
Share on other sites

Actually, if you want to use the XML serialization of the HTML 5 spec, no DOCTYPE is required usually.
According to this guy, a DOCTYPE is always necessary. (Scroll down a bit until you see the "Professor Markup Says" box.)That whole "diveintohtml5" site is awesome by the way.
Link to comment
Share on other sites

Guest FirefoxRocks
According to this guy, a DOCTYPE is always necessary. (Scroll down a bit until you see the "Professor Markup Says" box.)That whole "diveintohtml5" site is awesome by the way.
If you're using the XML serialization of HTML5, a DOCTYPE usually isn't necessary except for the reasons which are mentioned in the FAQ of which I quoted in my previous post.And browsers will still render the "XHTML5" document in standards mode instead of quirks mode because the "XHTML5" document must be served with a MIME type of "application/xhtml+xml", so the document is automatically rendered in quirks mode regardless of the DOCTYPE (or the lack of one).HTML5 documents must be served with the MIME type of text/html, so therefore a DOCTYPE is necessary to trigger standards mode. The HTML5 document isn't really a true DOCTYPE as it only contains the root element of the page (which is actually optional), and does not contain a PUBLIC nor SYSTEM identifier (feel free to correct me on this last statement).As for the original question of brackets, if you're using HTML5, tags like <link>, <meta> and <br> are closed using a >. If you are using "XHTML5", empty self-closing tags must be closed with />, otherwise your XML parser will throw an error.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...