Is <a href>some text</a> a valid html code?
This one some text is valid.
What about the first one? Is that a typo or it is allowed to skip =""?
The markup <a href>some text</a> is valid (and equivalent to some text) according to HTML5 CR in HTML serialization, but not otherwise.
General HTML5 rules on HTML serialization (HTML syntax) allow empty attribute syntax: “Just the attribute name. The value is implicitly the empty string.” And the empty string is a valid URL, referring to the current document.
In XHTML, <a href>some text</a> is invalid and not even well-formed, since well-formedness rules (i.e., general XML syntax rules) require that an attribute specicification is of the form name="value" or name='value', with no shortcuts.
In earlier HTML specs, up to and including HTML 4.01, <a href>some text</a> is invalid but on other grounds. By the formal rules, an attribute value may never be omitted from an attribute specification, but the name and the equals sign may be omitted, if the attribute is declared with an enumerated set of values. So <a href>some text</a> would be valid if there were an attribute for a declared with enumerated values so that one of them is href (and there is only one such attribute). But there is no such attribute.
It depends on your doctype. More importantly, the rendering depends on your client's browser implementation. Chrome, FF, IE>7, etc, these browsers know what you meant, and can pick up the pieces just fine.
HTML5
<!DOCTYPE html>
The validator says:
Valid, but WARNING: Attribute href without an explicit value seen. The attribute may be dropped by IE7.
XHTML1.0 Strict and XHTML1.0 Transitional
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
and
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
The validator says:
Invalid: "href" is not a member of a group specified for any attribute
HTML 4.01 Strict and HTML 4.01 Loose
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html>
and
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html>
The validator says:
Invalid: "HREF" is not a member of a group specified for any attribute
No it's not valid. Use:
<span class="pseudo-link">Some text</span>
and define styles in CSS for class pseudo-link to look like a normal link.
:hover selector will be important to change font color and underline the text when mouse is over it.
You can then define action for this pseudo-link with Javascript.
Related
I've been working with CQ5.6 for about a month now and our test site is almost done in terms of components.
However when we try to validate the pages we run into problems because AEM puts <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> above all our pages.
Now, I can't find any place where the Doctype is explicitly declared in our code. Nor is the HTML tag in our code, so i presume AEM wraps these around everything.
First I tried deleting the import of the doctype in our page component and replacing it with <!DOCTYPE html> but then we ended up with 2 doctype declarations. First the XHTML one, then a wrapped <html> tag and then my HTML5 one.
I've read in the docs that you can set the doctype using the cq:doctype property, but no clue where I should add that property to.
I also tried putting this above the head tags in our page components, but to no avail:
<% Doctype doc= Doctype.valueOf("HTML_5");
doc.toRequest(request);
%>
<%= Doctype.fromRequest(request).getDeclaration() %>
Could anyone explain to me how or where I could set the doctype to HTML5 for our project?
CQ doesn't wrap the page with Doctype by default. It might have been the case where your page component would have had foundation/components/page as its parent (sling:resourceSuperType property).
Due to the component hierarchy and inheritance, the Doctype included in the foundation page.jsp is getting included for your page, and hence it appears as if it is wrapping up your HTML.
The page.jsp includes doctype as shown below
<%= Doctype.fromRequest(request).getDeclaration() %>
You can avoid this by overriding the content of foundation page.jsp within your page component itself.
In this path foundation/components/page/_NAME_ you are able to override your head.jsp file which contains the DOCTYPE definition and the HEAD statements as well.
Next you can see an example of the original one:
head.jsp example
If you didn't define your own custom template, that's the reason. You may need to create a folder (/foundation/components/page/_NAME_/) with the next structure:
head.jsp
body.jsp
dialog.xml
I declared rel="value" attribute for <li> element in DTD like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" [<!ATTLIST li rel CDATA #IMPLIED>]>
After that my code with <li rel="value"></li> was valid, but I got another issuer: Browser renders "]>" character in document.
How to fix this?
You should not use an internal subset in a doctype declaration, because browsers do not understand it, or DTDs at all.
If you use a simple added attribute, for some reason, it is often best to just be careful enough with it, or “check it manually”. But to perform DTD-based validation, you would need to construct an external DTD, based on the DTD you wish to use as basis, and with the extra markup added into it. In this case, you would copy the HTML 4.01 Transitional DTD and replace
<!ATTLIST LI
%attrs;>
by
<!ATTLIST LI
rel CDATA #IMPLIED
%attrs;>
(That is, you need to provide the full list of allowed attributes, with your custom attribute added, instead of declarign an attribute list that only allows your attribute [unless that’s what you really want].)
You would then use a doctype declaration that refers to your modified copy by its URL, with
<!DOCTYPE HTML SYSTEM "dtdurl">
where dtdurl is an absolute URL for the DTD. More info: Creating your own DTD for HTML validation.
It is generally not advisable to add attributes of your own, as they may clash with attributes that might be added to HTML in some future version. According to HTML5 drafts, attributes with names starting with data- are meant for site-specific use and will never have any publicly defined meaning, so data-rel would be safer than rel.
Browsers don't understand embedded SGML. They simply stop reading the doctype at the first > character. So they see the following ]> as text to be rendered.
Just don't use embedded SGML.
Use a pseudo-attribute > delimiter instead of a literal > delimiter to escape the nested > within ]>:
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"
[<!ATTLIST li rel CDATA #IMPLIED>]>
References
Pseudo-Attributes
I have a html document:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" >
In it I have tags such as
<br />
But Im reading that this tag is an XHTML element. Yet it still works why?
Original answer based on the question as written before a character was moved and completely changed it:
But Im reading that </br> is an XHTML element.
It isn't. Is is the end tag for an element.
<br /> would be a self closing tag (representing an entire element) in XHTML. In HTML 4 it means the same as <br>> (although most browsers don't respect that) and in HTML 5 the / is meaningless syntactic sugar to keep people used to XHTML happy.
In XHTML <br/> means the same as <br></br> (the latter is an error in HTML documents).
Yet it still works why?
Browsers perform enormous amounts of error correction to try to deal with the sort of bad markup that was prevalent in the late 90s.
They are not always consistent in how they recover from different errors (for example, I believe that some browsers will ignore that completely while others will treat it as a line break), so you should never depend on this behaviour.
Browsers failed to implement parsers that correctly handled HTML 4 and earlier.
They should have treated <br/> as "A br element followed by a greater than sign", but instead implemented it as "A br element with a / attribute, what's a / attribute? We'll drop it". This led to the feature being marked as something to avoid.
XHTML then exploited the bug for HTML-Compatible XHTML.
HTML 5 then redefined it as syntactic sugar so the XHTML junkies could keep on using the syntax they were used to.
It's the browser that get rid of these differences. Anyways the </br> with that slash is incorrect both in HTML and XHTML.
Occurring to http://www.w3schools.com/tags/tag_br.asp
In HTML the <br> tag has no end tag.
In XHTML the <br> tag must be properly
closed, like this: <br />.
Self closing tag is valid format in XML
XHTML means all tag must be closed
HTML
<br> valid
<br/> valid
XHTML
<br> invalid
<br/> valid
Edited:
</br> is invalid anyway and you are lucky if browser fix it :)
</br> is the same as <div id="gd"/>, both are invalid
I have 12 errors, but some are just pure non existent. I'm using the smarty templating engine.
Doctype:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Here's the error report, but the "duplicate specification of attribute "value"" simply isn't true according to my .tpl: jsfiddle of .tpl here
{textfield class="quetext" value="Epost*" onblur="if(this.value=='')
this.value='Epost*';"
onfocus="if(this.value=='Epost*') this.value='';"}
Also, does a textarea require the attribute "rows" and "cols"? I thought that was only for tables?
And I don't understand what the two errors at the end mean:
Line 586, Column 80: Attribute value redefined...
Please help!
Thanks :)
(Sorry if things chop and change, I'm working on the valdiation now, to tidy up as many errors as possible.)
the "duplicate specification of attribute "value"" simply isn't true according to my .tpl:
The validator is only looking at your output. You have the value attribute in there twice, no matter what you .tpl says.
Also, does a textarea require the attribute "rows" and "cols"?
Yes
I thought that was only for tables?
Tables don't have those attributes at all
Line 586, Column 80: Attribute value redefined...
You have, in essence: <foo value="something" value="something">
This is the same problem as before, except it is the error on the second one rather than the first.
Following declaration appears in html 4.01 dtds
<!ELEMENT STYLE - - %StyleSheet -- style info -->
(see http://www.w3.org/TR/REC-html40/sgml/dtd.html it's in both strict.dtd and loose.dtd)
Apparently, the ; is missing after %StyleSheet. The reference should have been %StyleSheet;
But this is the official dtd of the holy html - by far the most important dtd of all dtds - so what's going on there? Is it valid entity reference like that?
It is valid without the semicolon in HTML 4.01 DTDs. Here's an extract from the W3C's HTML 4.01 Specification - On SGML and HTML:
... Instances of parameter entities in a DTD begin with "%", then the parameter entity name, and terminated by an optional ";".
In an XHTML DTD it wouldn't be valid; they follow this recommendation (because XHTML is XML): Extensible Markup Language (XML) 1.0 (Fifth Edition) - Character and Entity References:
... Definition: Parameter-entity references use percent-sign (%) and semicolon (;) as delimiters.