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>
Related
This question already has answers here:
What is the functionality of !DOCTYPE?
(5 answers)
Closed 5 years ago.
The <!DOCTYPE html> tag must be present at the beginning of an HTML document. Can I know the reason why? Also, I've noticed that my webpage works all fine even without this tag.
Here is a sample code along with the tag.
<!doctype html>
<html>
<head>
</head>
<body>
Hello, world!
</body>
</html>
Here is the code without the tag.
<html>
<head>
</head>
<body>
Hello, world!
</body>
</html>
Both of the codes return the same result. What is the actual purpose of the tag and what will happen if it is not present in an HTML code?
The <!DOCTYPE> declaration must be the very first thing in your HTML document, before the tag.
The <!DOCTYPE> declaration is not an HTML tag; it is an instruction to the web browser about what version of HTML the page is written in.
In HTML 4.01, the <!DOCTYPE> declaration refers to a DTD, because HTML 4.01 was based on SGML. The DTD specifies the rules for the markup language, so that the browsers render the content correctly.
HTML5 is not based on SGML, and therefore does not require a reference to a DTD.
source
DTD-Document Type Definition.
also take look at previous answers
Firstly, you've to know doctype declaration is not a tag, but an instructor that tells the browser which version of html you are using or you want use.
In HTML 4.01 doctype declaration refers DTD, The DTD define complete rules for the mark up languages because HTML 4.01 based on SGML.
Html 5 or current version of html does not require the doctype declaration because it does not based on SGML.
But its better always to add the Doctype declaration to your html document so that the browser will understand which type html expect to.
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.
The HTML validator I found today - http://html5.validator.nu/ - says that my use of the <noscript> element is wrong. My XHTML source code is like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
<body>
<div id="head">
<noscript>
<p>JavaScript is disabled.</p>
</noscript>
...
The error message from the validator is this:
Error: XHTML element noscript not allowed as child of XHTML element div in this context. (Suppressing further errors from this subtree.)
Contexts in which element noscript may be used:
In a head element of an HTML document, if there are no ancestor noscript elements.
Where phrasing content is expected in HTML documents, if there are no ancestor noscript elements.
Content model for element div:
Flow content.
Now I went on to the Mozilla Documentation and tried to understand what that means. I have found some information about content categories, flow content, phrasing content, what elements belong to each category (whatever "belong" means exactly) and how the <noscript> element may be used. (https://developer.mozilla.org/en/HTML/Element/noscript)
I now know this: <div> must contain flow content. <noscript> must occur in phrasing content. That obviously doesn't match. How can I manage that? Many elements are in both, flow and phrasing, categories though. They don't seem to be disjunct sets, so some can't decide or I don't get it.
How does the HTML specification intend to solve this quirks?
You shouldn’t use an HTML5 validator to validate your XHTML 1.1 document.
The HTML5 spec says about the noscript element:
The noscript element must not be used in XML documents.
So noscript inside div isn’t allowed in XHTML5, but it’s allowed in XHTML 1.1.
You can't use "noscript" in an XHTML/XML document because it disables the parser for the "noscript" content and you can't do that in XML. The parser cannot be temporarily disabled or turned off.
For example, CSE HTML Validator generates this message for XHTML documents:
XHTML documents must not use the "noscript" element. This is because the way "noscript" works by "turning off" the parser when scripts are enabled, which can't be done in XML. Also, the "noscript" element is explicity not allowed in HTML5 for this reason.
If you want to use "noscript" properly, then you'll need to change the document type to HTML5 (recommended) or HTML4 instead of XHTML.
Use the official validator to validate your HTML. The following code validated perfectly fine for me:
<!DOCTYPE html>
<html>
<head>
<title>I AM YOUR DOCUMENT TITLE REPLACE ME</title>
</head>
<body>
<div id="head">
<noscript>
<p>JavaScript is disabled.</p>
</noscript>
</div>
</body>
</html>
EDIT: Interestingly, the W3C validator claims that the parser is based on the validator at the link you provided.
'The uploaded document was successfully checked as HTML5. This means that the resource in question identified itself as "HTML5" and that we successfully performed a formal validation of it. The parser implementations we used for this check are based on validator.nu (HTML5).'
Perhaps the validator at http://validator.nu is an older version. Edit edit: Nope, it validates just fine there too. Checked as HTML5 and XHTML 1.0 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.
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>