Im having an issue with custom attrubutes in html5 document.
My source code starts with the following code:
<!DOCTYPE html
[
<!ATTLIST img pid ID #IMPLIED>
]>
When im trying to validate my html file in W3C validator it doesnt determine my documents doctype and tells that my doctype declaration is wrong.
So my question is, how can I declare custom attributes in HTML5? Is it even possible at the moment in HTML5? I couldnt find any relevant information on the internet.
The DOCTYPE you are trying is invalid, it should be <!DOCTYPE html> which is a valid doctype for HTML5 and as far as the custom attributes go, you need to use data- prefix which will be considered as valid custom attribute.
<p data-custom-attribute="Value"></p>
[1] A custom data attribute is an attribute in no namespace whose name
starts with the string data-, has at least one character after the
hyphen, is XML-compatible, and contains no uppercase ASCII letters.
1. Reference
Related
The Google+ JS API shows credentials and settings can be set using meta tags instead of passing through a JS call. Examples:
<meta name="google-signin-clientid" content="CLIENT_ID" />
<meta name="google-signin-cookiepolicy" content="single_host_origin" />
I tried this on my website and it works, but when I try to
validate my HTML the validator gives errors such as:
Bad value google-signin-callback for attribute name on element meta:
Keyword google-signin-callback is not registered.
Bad value google-signin-clientid for attribute name on element meta:
Keyword google-signin-clientid is not registered.
Bad value google-signin-cookiepolicy for attribute name on element
meta: Keyword google-signin-cookiepolicy is not registered.
Bad value google-signin-scope for attribute name on element meta:
Keyword google-signin-scope is not registered.
Is the HTML code Google provides as an example really invalid?
You are validating against HTML5 (this can be seen from the error messages), and as per HTML5 drafts, only a limited set of name attribute values are allowed in a meta element. So as an HTML5 document, the document is invalid, since the values used are among those allowed. HTML5 defines a registration procedure, but apparently Google cannot be bothered to use it.
If you validate against XHTML 1.0, the code will pass, because in XHTML 1.0, the name attribute value can be any name, like <meta name="Hi, I’m trying to make a point” content="" />. The same applies to HTML 4.01, except that the slash before “/” would cause a syntax error in it.
It's valid HTML, the names being used are not part of the official standard. That's fine though since they are namespaced with google so you shouldn't have any issues.
My website is almost ready but I notice that my website shows in Firefox and IE look different and in chrome is fine. I have used HTML Validation to check and have 2 errors and 2 warnings. This is the details :
Line 2, Column 13: there is no attribute "XMLNS"
<html xmlns="http://www.w3.org/1999/xhtml">
✉
You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. 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 "Transitional" document type to get the "target" attribute), or by using vendor proprietary extensions such as "marginheight" (this is usually fixed by using CSS to achieve the desired effect instead).
This error may also result if the element itself is not supported in the document type you are using, as an undefined element will have no supported attributes; in this case, see the element-undefined error message for further information.
How to fix: check the spelling and case of the element and attribute, (Remember XHTML is all lower-case) and/or check that they are both allowed in the chosen document type, and/or use CSS instead of this attribute. If you received this error when using the element to incorporate flash media in a Web page, see the FAQ item on valid flash.
Line 4, Column 76: NET-enabling start-tag requires SHORTTAG YES
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
✉
For the current document, the validator interprets strings like according to legacy rules that break the expectations of most authors and thus cause confusing warnings and error messages from the validator. This interpretation is triggered by HTML 4 documents or other SGML-based HTML documents. To avoid the messages, simply remove the "/" character in such contexts. NB: If you expect to be interpreted as an XML-compatible "self-closing" tag, then you need to use XHTML or HTML5.
This warning and related errors may also be caused by an unquoted attribute value containing one or more "/". Example: http://w3c.org>W3C. In such cases, the solution is to put quotation marks around the value.
Line 4, Column 77: character data is not allowed here
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
✉
You have used character data somewhere it is not permitted to appear. Mistakes that can cause this error include:
putting text directly in the body of the document without wrapping it in a container element (such as a aragraph), or forgetting to quote an attribute value (where characters such as "%" and "/" are common, but cannot appear without surrounding quotes), or using XHTML-style self-closing tags (such as ) in HTML 4.01 or earlier. To fix, remove the extra slash ('/') character. For more information about the reasons for this, see Empty elements in SGML, HTML, XML, and XHTML.
Line 44, Column 12: NET-enabling start-tag requires SHORTTAG YES
<br/>
✉
For the current document, the validator interprets strings like according to legacy rules that break the expectations of most authors and thus cause confusing warnings and error messages from the validator. This interpretation is triggered by HTML 4 documents or other SGML-based HTML documents. To avoid the messages, simply remove the "/" character in such contexts. NB: If you expect to be interpreted as an XML-compatible "self-closing" tag, then you need to use XHTML or HTML5.
This warning and related errors may also be caused by an unquoted attribute value containing one or more "/". Example: http://w3c.org>W3C. In such cases, the solution is to put quotation marks around the value.
As for Line 2, Column 13, I have added in this under header.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
However, this error is still there and I really do not know how to tidy it. On top of that, I am not a programmer and very poor in HTML....
Thank you.
You are trying to validate a document with some XHTML features as HTML 4. You are not showing the first line of the HTML document, and this would be all-important. In general, you should show a complete HTML document that reproduces the issue. But in this case, the apparent reason is wrong DOCTYPE. You should replace the existing HTML 4 DOCTYPE by one that declares some version of XHTML 1.0, if XHTML 1.0 is what you are trying to use.
When validating my page, the W3-Validator gives me an error for every
<tag addthis:title="AddThis share title" />
attribute in my code. How can I make those attributes valid for HTML5, so the page validates? I need those tags so addthis uses the correct titles for my sharing links, so I can't get rid of them...
I'd have to assume that "addthis" is an XML namespace; does the html tag declare something like <html xmlns:addthis="..">? If not, it won't validate because the namespace is undefined for the document. If so, it won't validate because "addthis" isn't a standard namespace.
See: http://www.w3.org/TR/2011/WD-html5-20110405/namespaces.html
Confounded to your troubles is the fact that "the HTML syntax does not support namespace declarations, even in foreign elements."
Check out http://www.w3.org/TR/2011/WD-html5-20110405/syntax.html#elements-0 , the cdr:license example.
Unfortunately (in your case) HTML5 isn't XML, so XML namespaces aren't necessarily valid in HTML5. Your only real option is to ignore the validation error.
Not unrelated question: HTML5 validator failing on Facebook OpenGraph XML Namespace xmlns:og
Oh, and while you're there, the <tag /> syntax is also XML, not HTML5.
You can't make them valid. Not in HTML, not in XHTML. The only valid custom attributes allowed in HTML5 start "data-".
You could make your markup valid HTML5+something or XHTML5+something, but getting a validator to check for that is a non-trivial task.
Do most modern browsers support ids in script tags such as:
<script id="aParticularScript">/* ... */</script>
The reason I ask is that Eclipse displays a warning stating "undefined attribute name" but it works fine in Google Chrome when I use jQuery selectors to get other properties of the script element. W3Schools states that the script element does not support any standard attributes (including the id attribute), but I've learned not to trust W3Schools.
Is it okay to have the script tag have an id?
HTML 4 Answer:
No, you can't, at least not if you want valid HTML...
The following elements can't have an ID attribute:
<base>
<head>
<html>
<meta>
<script>
<style>
<title>
There might be a couple more.
This is confusing because viewing just the documentation for the ID/class attributes doesn't specifically say that they can't be used with these elements. You have to look at the DTD for the elements to see that the general attributes are not defined for the element, and thus cannot be used.
HTML 5 Answer:
The default document type declaration, HTMLElement, which applies to all elements in HTML specifies that these global attributes (including the ID attribute) can be used on any element you create, so it would appear you can do this in HTML 5, but not in HTML 4.
Running a <script> tag with an id through the validator as HTML4 generates this error:
Error Line 12, Column 12: there is no attribute "ID"
The HTML4 specification for <script> does not mention the coreattrs (that include class and id) to be valid on this element:
18.2.1 The SCRIPT element
<!ELEMENT SCRIPT - - %Script; -- script statements -->
<!ATTLIST SCRIPT
charset %Charset; #IMPLIED -- char encoding of linked resource --
type %ContentType; #REQUIRED -- content type of script language --
src %URI; #IMPLIED -- URI for an external script --
defer (defer) #IMPLIED -- UA may defer execution of script --
>
Start tag: required, End tag: required
According to the current HTML5 spec, <script> may have any Global Attributes which does include id. Testing this in an unofficial HTML5 validator passes. So as far as I can tell:
Invalid in HTML4
Valid in HTML5
When i validating my site i got following issue
<embed src="banner.swf" quality="high" pluginspage="http://www.macromedia…
✉
You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. 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 "Transitional" document type to get the "target" attribute), or by using vendor proprietary extensions such as "marginheight" (this is usually fixed by using CSS to achieve the desired effect instead).
This error may also result if the element itself is not supported in the document type you are using, as an undefined element will have no supported attributes; in this case, see the element-undefined error message for further information.
How to fix: check the spelling and case of the element and attribute, (Remember XHTML is all lower-case) and/or check that they are both allowed in the chosen document type, and/or use CSS instead of this attribute. If you received this error when using the element to incorporate flash media in a Web page, see the FAQ item on valid flash.
How Can i solve this???
<embed> is deprecated, you should use <object> instead.
See http://www.w3.org/TR/REC-html40/struct/objects.html#h-13.3
embed isn't part of the HTML 4.0 or XHTML 1.0 specification (although it is part of HTML5). The object tag is the standardized tag to embed Flash and similar content in a webpage.