is this allowed?
<style id="my_id_0" type="text/css"> ...
According to the XHTML 1.0 Strict DTD it is allowed but how it is actually supported by browsers (especially when the style-tag is used within the head) is another question.
It depends which markup language you are using.
It is not allowed in HTML 4.01.
It is allowed in XHTML 1.0 (this looks like one of many changes that the working group decided to implement without a mention in the differences from HTML 4.01 section)
It is allowed in the HTML 5 draft
Not allowed according to W3C. Just wrap your <style> tag with <span></span>
Related
I want to use different CSS selectors for every language. I've got an HTML document like:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es">
...
</html>
I have got different languages, and I want to change the style depending on the language.
I've tried html:lang(es) but it doesn't work.
The xml:lang attribute will only be effective when the XHTML is interpreted as XML. When it is being parsed as HTML, you need to use the lang attribute.
You can test this by saving your XHTML document locally with a XML file extension and then loading in the browser, and the current CSS selector should work.
If you can control the generation of the XHTML, the easiest thing to do is to use both of the language attributes, to ensure that it is evaluated properly when read as either XML or HTML.
This is described in the W3C international Declaring language in HTML page:
When serving XHTML 1.x or polyglot pages as text/html, use both the lang attribute and the xml:lang attribute together every time you want to set the language. The xml:lang attribute is the standard way to identify language information in XML. Ensure that the values for both attributes are identical.
<html lang="fr" xml:lang="fr" xmlns="http://www.w3.org/1999/xhtml">
The xml:lang attribute is not actually useful for handling the file as HTML, but takes over from the lang attribute any time you process or serve the document as XML. The lang attribute is allowed by the syntax of XHTML, and may also be recognized by browsers. When using other XML parsers, however (such as the lang() function in XSLT) you can't rely on the lang attribute being recognized.
I recommend updating the language attribute in the html aswell. You could select this element using CSS aswell. xml is an attribute that you can select with CSS.
html[xml:lang="es"]{ //your style }
You could also use change the css with the lang attribute
html[lang="es"]{ //your style }
html[xml\:lang="es"] body{ background: red; }
html[xml\:lang="en"] body{ background: green; }
<html xml:lang="es" lang="es">
<head>
</head>
<body>
</body>
HTML does normally allow to have no spaces between attributes when attributes have values and those values are quoted.
Example (Reference/Source):
In HTML-documents no White Spaces between Attributes are needed.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>no attribute space</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p class="CLASS"title='TITLE'></p>
</body>
</html>
See the third-last line:
<p class="CLASS"title='TITLE'></p>
^^
Now using such HTML chunk changing the doctype to HTML 5 (<!DOCTYPE HTML>), makes the experimental W3C HTML 5 conformance checker give an error exactly there telling me:
Validation Output: 1 Error
Error Line 9, Column 22: No space between attributes.
<p class="CLASS"title='TITLE'></p>
^
So I thought that HTML 5 is backwards compatible to how browsers deal with HTML in reality and browsers AFAIK deal with this well. So I'm a bit puzzeled at least. I also have problems to decipher the (somewhat needlessly) compilcated HTML 5 specs to be precise at this point because what I did find (W3C again, see http://www.w3.org/TR/html-markup/syntax.html#syntax-attributes) it's not saying that this is (may nor must) be an error.
You are reading a discontinued, non-normative reference. If you look at the definition of the start tag in the specification (which is normative) it says:
Then, the start tag may have a number of attributes, the syntax for which is described below. Attributes must be separated from each other by one or more space characters.
So I thought that HTML 5 is backwards compatible to how browsers deal with HTML in reality and browsers AFAIK deal with this well.
Being compatible with real world markup is a design goal, but lots of things have been obsoleted and leaving out the space between attributes is something that almost never occurs intentionally.
Section 4.3, "Elements" of the document you link in the question says:
Optionally, one or more attributes, each of which must be preceded by
one or more space characters.
Usin the W3C Official HTML Validator, having no spaces between attributes are checked as errors if you use the HTML5 Doctype:
<!DOCTYPE html>
The output message is the following:
Line 9, Column 23: No space between attributes.
I have the following at the top of my document:
<html class="js" lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
Can someone tell me if I need the xmlns part? I am not 100% sure but I think this is
doing some things to my tags. For example when I look at the tag is see the
following with firebug:
element.style {
height: 100%;
}
If I just have this as at the top of my code then I don't see the element.style ..
<html class="js" lang="en">
Just to give some background. I'm developing an MVC application for use with English. It uses HTML5 things in a few places.
For the current html spec, (which is html5) you will not need any fancy attributes, the following is adequate:
<!DOCTYPE html>
<html>
<head>
<title>Html page</title>
</head>
<body>
<p>This is an example Html page.</p>
</body>
</html>
Also, if you are not using the html5 spec, you should.
If you are using HTML5, then the extra tags probably should not be there as they are not needed any longer.. HTML5 uses a much cleaner syntax. :)
Here is the W3 documentation about this
You do not need to give those attributes in the tag.
<html>
</html>
will work fine even in HTML5 or HTML 4.01
The xmlns attribute may be needed if the document will be processed by XML tools that do not necessarily use HTML namespace as the default. You can see this by saving the document locally and opening it in Firefox; if the xmlns attribute is missing, Firefox will display the document source, just with XML syntax coloring, because it treats all tags just as pure markup with do meaning or default rendering rules.
If the document is served as HTML (Content-Type: text/html), then browsers will imply HTML semantics (HTML namespace).
Regarding the question you asked in the heading, you should put a doctype declaration, such as <!DOCTYPE html>, for all new documents. Otherwise you will trigger Quirks Mode, which means a large and undocumented set of oddities.
When take some tutorial from web, I see many people leaves tags open like <link ..>, <img ..>. But when I use Netbeans to edit them (the HTML/JSP pages), it show a red background on those tags until I add the slash into them. <br> --> <br/>.
Which is the correct way to write HTML-based code?
Both are fine for HTML. Though not for XHTML which is an XML dialect.
Some elements do not need a closing (/>) tag - in particular empty elements (those that do not have content). Examples are <hr> and <br>. These can also be self closing (<hr /> and <br />, respectively). This self closing is equivalent to having a close tag immediately after the open tag.
For XML, such a non closing tag is not valid - it must be closed, either self closing or have a closing tag. So <hr> is not valid XML, but <hr /> and <hr></hr> are.
HTML is not XML, but for better compatibility some tools try to emit as much XML like HTML as possible.
It depends which DOCTYPE you're using. If you're using HTML 4 then you shouldn't use self-closing tags, if XHTML then you should to make valid XML, and if HTML 5 then closing slashes are optional, but not required.
The W3C HTML Validator will throw a warning if you try to use closing tags in HTML 4:
The sequence can be
interpreted in at least two different
ways, depending on the DOCTYPE of the
document. For HTML 4.01 Strict, the
'/' terminates the tag '). However, since many
browsers don't interpret it this way,
even in the presence of an HTML 4.01
Strict DOCTYPE, it is best to avoid it
completely in pure HTML documents and
reserve its use solely for those
written in XHTML.
> is correct for HTML, but incorrect for XHTML. Check your DOCTYPE.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
for HTML strict
and
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
for XHTML strict
I was just checking to see if it was valid to put an <iframe> element inside a <noscript> element as a fall back for displaying dynamic content. It validated fine with the HTML 5 doctype, but for HTML 4.01, I get the following error:
Line 9, Column 35: element "IFRAME" undefined
<iframe name="test" src="test.htm"></iframe>
You have used the element named above in your document, but the document type you are using does not define an element of that name. This error is often caused by:
incorrect use of the "Strict" document type with a document that uses frames (e.g. you must use the "Frameset" document type to get the "" element),
by using vendor proprietary extensions such as "" or "" (this is usually fixed by using CSS to achieve the desired effect instead).
by using upper-case tags in XHTML (in XHTML attributes and elements must be all lower-case).
This is what I whittled the HTML down to:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>I AM YOUR DOCUMENT TITLE REPLACE ME</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div>
<iframe name="test" src="test.htm"></iframe>
</div>
</body>
</html>
The <iframe> element is defined in the HTML 4.01 specification at the following URL: http://www.w3.org/TR/html401/present/frames.html#h-16.5.
It passes with a transitional doctype, so I guess my question is "Why is it disallowed in a strict doctype, even though it's defined in the specification?".
"Why is it disallowed in a strict doctype, even though it's defined in the specification?
Lots of things are defined in the specification but not allowed in Strict. <font> springs to mind. These are the things that the developers of the specification considered in need of documenting, were in use in browsers in the day, but which should be transitioned away from.
I can think of two reasons why they might have thought that:
"Why do iframes suck?".
<iframe> does (in theory) little that can't be achieved with <object>
iframe isn't included in html strict. For validation, try using the object element instead.
<object data="test.html" type="text/html"></object>
You should also add width and height attributes to the object element. Note, unlike iframes objects cannot be a target for any page links.
Unless for some reason you specifically need html4 strict validation, it's better to use the html5 doctype.