Html code validation problems - html

I am facing problem with html code validation. My code is like:
`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
Remove this if you use the .htaccess -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
</head>
<body>
<!---this is a comment----->
</body>
</html>`
It shows me an error. The error code is :
Consecutive hyphens did not terminate a comment. -- is not permitted inside a comment, but e.g. - - is.
what was the problem in my comment?? Please help

When you have multiple dashes, this causes the HTML parser to think that the comment has ended, so it starts looking for a > which it cannot find.
So, when using comments, just use two dashed before and after, and never use two dashes in a row in the comment text itself.
This is formally not allowed, according to the specs:
4.7. Comments # T
Comments consist of the following parts, in exactly the following order:
the comment start delimiter "<!--"
text
the comment end delimiter "-->"
The text part of comments has the following restrictions:
must not start with a ">" character
must not start with the string "->"
must not contain the string "--"
must not end with a "-" character
The following is an example of a comment.
<!-- main content starts here -->
Your comment violates both the rules that I made bold.

Related

HTML how to get it to display čšž on your site

Trying to learn to make a site. And right from the start:
How do I get HTML to display ščž and other various special characters like ł,ß,ö..?
You need to specify a character set so the browser knows what's being used in the page. For example, in your head section, try putting:-
<meta charset="UTF-8">
You can also try specifying symbols using their entity name/code, using the character reference table here - https://dev.w3.org/html5/html-author/charref
Here's an HTML5 example. meta declares the encoding of the HTML file. Make sure to save the file in that encoding!
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Example</title>
</head>
<body>How do I get HTML to display ščž and other various special characters like ł,ß,ö,&#x9A6C..?</body>
</html>
You can enter any character you know the Unicode codepoint using &#xnnnn syntax. In the example above, U+9A6C is the Chinese character for horse(马).

What form of meta tag is valid in HTML5 <meta> or <meta/>?

Validators accept both form of tag <meta> and <meta/>. HTML5 specification says that no end tag should be present, hence the form of <meta><meta/> is prohibited. But I could not find any information about form <meta/>.
As per this HTML5 standard: http://www.w3.org/TR/html-markup/syntax.html#void-element
Start tags consist of the following parts, in exactly the following
order:
A "<" character.
The element’s tag name.
Optionally, one or more attributes, each of which must be preceded by one or more space characters.
Optionally, one or more space characters.
Optionally, a "/" character, which may be present only if the element is a void element.
A ">" character.
The meta is a void element and hence the part #5 would apply with a caveat that "optionally, a / character, which may be present..."
<meta ... />
And so, you may omit the part #5 i.e. the closing "/", and hence this is also valid:
<meta ... >
Further down the spec says:
Void elements only have a start tag; end tags must not be specified
for void elements.
To summarize, end tag is not required. Self closing is not required. It will not hurt if end tag or self-close is present.
.
It depends on whether you use HTML5 or XHTML5 syntax. In XHTML5 it is required and the parser will freak out if you don't use / when closing tag. Generaly all XML elements must have closing tag.
Try this snippet of code in Validator.nu
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Document</title>
<meta charset="UTF-8"/>
</head>
<body>
</body>
</html>
Try to remove / from meta charset and observe the result. Don't forget to set correct preset for XHTML5.
Looking at Mozilla's documentation for it, as well as from what I've observed in general, you just don't close the tag.
<meta charset="utf-8">
The above is valid HTML5. There's no reason to include any sort of close tag or anything resembling a closing tag on it.

Having 2 <head> in 1 page

I have 2 <head> tags in one web page. Reason is that I used to have the header, the content and the footer views loaded separately, so I left 1 <head> in the header view and another in the content view.
What's the effect of this? If it's not compliant with html standard, then should I get rid of all extra <head> and only leave 1 in 1 page?
This is what HTML looks like:
<!DOCTYPE html>
<html>
<head><!-- The *required* head -->
<title>The *required* title</title>
</head>
<body><!-- The *required* body -->
Stuff
</body>
</html>
Don't do anything besides that - that includes using two head tags. I think what you want is iframes.
Here's specifically what happens, when an HTML5-compliant browser parses a document with two head elements:
gets to the first </head> tag: The "after head" insertion mode
encounters the second <head> tag: "Parse error. Ignore the token."
encounters some other tags, e.g. <meta>: Parse error, but it basically adds the tag to the previous head element.
encounters second </head> tag: "Parse error. Ignore the token."
So what does this mean? It is a parse error to have multiple heads. However, the standard is clear on what should happen in this case. It does the "right" thing and merges the them.
I should also point out that <head></head> tags are optional. You can leave them out and have no parse errors.

The reference to entity "subset" must end with the ';' delimiter [duplicate]

This question already has answers here:
The reference to entity "foo" must end with the ';' delimiter
(2 answers)
Closed 6 years ago.
I am trying to include webfonts in the template of a Blogger blog:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html b:version='2' class='v2' expr:dir='data:blog.languageDirection' xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xmlns:expr='http://www.google.com/2005/gml/expr'>
<head>
<link href='http://fonts.googleapis.com/css?family=Share:400,700&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Istok+Web:400,700&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<meta content='IE=EmulateIE7' http-equiv='X-UA-Compatible'/>
<b:if cond='data:blog.isMobile'>
<meta content='width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0' name='viewport'/>
<b:else/>
And when I try to save the template, I get:
Error parsing XML, line 5, column 76: The reference to entity "subset" must end with the ';' delimiter.
I tried to add a ; but unsuccessfully. The links are generated and taken from Google Web Font.
How should I solve this issue? Thanks.
That's because & is a reserved character in XML that means "an XML entity begins here". XML entities let you print characters or sequences of characters that are hard for you to embed in your document literally, either because you don't have it on your keyboard or because the document encoding forbids it. For instance, in (X)HTML, é prints the character "é", which is not easy to find on most US keyboard. (Available entities depend on the <!DOCTYPE> declaration of your XML document.)
The problem with that scheme is that it means you can't unambiguously leave literal & characters around your document if they can be the start of an entity, so you need to encode them as an entity to solve that problem.
You will need to replace all your stray & with &, which will print & without angering the XML parser. In your case, you should be good with replacing &subset= by &subset= in your two <link> tags.
Ampersands in XML indicate the start of an entity reference. It starts with an ampersand, then there's a marker indicating which entity it is referring to, then a semicolon to end it. In order to include a literal ampersand in a document, you need to use a character entity reference that refers to an ampersand, i.e. &.
As you have not done this, the parser is trying to parse the following data as if it were an entity reference, which it is not. That is why it fails to parse - it can't find the semi-colon at the end of the entity reference because it's not supposed to be an entity reference.
For instance, where you have:
http://fonts.googleapis.com/css?family=Share:400,700&subset=latin,latin-ext
You should have:
http://fonts.googleapis.com/css?family=Share:400,700&subset=latin,latin-ext

Is this minimalist HTML5 markup valid?

<!DOCTYPE html>
<meta charset="utf-8">
<body>
Hello, world!
SOURCE FOR CODE
If so, besides removing "Hello, world!" is there any tag that's able to be removed and it still be valid, and how do you know it's still valid?
It's not valid. To check it you can run it in W3C Validator
The error is: Element head is missing a required instance of child element title.
...
UPDATE
As vcsjones stated the head element is optional. That's the title one is required. Credit to mootinator for pointing out that the body is also optional.
So the simplest valid document will be:
<!DOCTYPE html>
<title></title>
(Assuming the HTML syntax of HTML5.)
Note that in some situations the title element is optional, too.
From HTML5’s definition of head:
The title element is a required child in most situations, but when a higher-level protocol provides title information, e.g. in the Subject line of an e-mail when HTML is used as an e-mail authoring format, the title element can be omitted.
So the minimal markup for a document that gets a title from a "higher-level protocol" is this:
<!DOCTYPE html>
If the document is the value of an iframe-srcdoc it’s this (assuming a title is provided by the container document):
<html>
And for a stand-alone document it’s this (the title element needs some actual content, as noted by kapep, so the "…" is just an example):
<!DOCTYPE html>
<title>…</title>
The title tag can't be empty or only consist of whitespace. So if the document is in a context where the title tag is required, you will have to set a valid title value.
The title content model is defined as "Text that is not inter-element whitespace".
"Empty Text nodes and Text nodes consisting of just sequences of [space characters]" are inter-element whitespace. Space characters are space, tab, line feed, form feed and carriage return.
If the title tag is empty, the W3C Validator complains that "Element title must not be empty". The Validator is fine with only adding just spaces, even though that is not correct according to the specs.
It is valid if you add another non-space character:
<!DOCTYPE html>
<title>x</title>
You could use other space characters like non-break space or zero-width non-break space if you want to fake an "empty" title.
The smallest HTML document for which the Nu Html Checker (the only HTML validator currently endorsed by the WHATWG) does not produce any errors nor warnings is the following:
<!DOCTYPE html>
<html lang="">
<title>x</title>