Recently the W3C HTML5 validator started telling me I should not used self-closing tags:
"Self-closing tag syntax in text/html documents is widely discouraged; it’s unnecessary and interacts badly with other HTML features (e.g., unquoted attribute values). If you’re using a tool that injects self-closing tag syntax into all void elements, without any option to prevent it from doing so, then consider switching to a different tool."
This applies to for examle the tags that are inserted by Joomla (4) when we use $doc->addHeadLink. This inserts a link tag with that is self closing. When we want HTML validation (form W3C) we need to have those unclosed because this is a void tag that van never have any content. Browser will render this OK but accoriding to the warning this might in some cases cause issues.
I am not sure if this has been discussed before and also I am not sure how important this is. Just wanted to put it out there.
For the $doc->addHeadLink the output should then be changed to omit the closing tag.
Should Joomla (4) be able to output sel-closing tags that are HTML5 proof? Eventhought it does not cauze any issues at the moment?
Labels |
Added:
No Code Attached Yet
|
I use joomla 3.10.11 and set in template $doc->setHtml5(true);
but in result have not valid self-closing tags in header, like this <meta charset="utf-8" />
how to fix this bug?
I don't think this is a bug, but a change in HTML5 validation checks. It won't do any harm, but I do thinkt the Joomla output should somehow be able to produce selfclosng tags that are valid HTML5. I do thnk when these tags (like br,img, etc) omit the closing tag they will stille be OK for older browsers / templates as well. I think modern browsers will just ignore te closing slash, but again it's not vaild HTML5. In the future that might become an issue in browsers. The W3C HTML5 validation check now shows these 'errors'. I did not before.
Also I think Joomla 3 will not be changed with regards to this issue. But maybe J4 will.
Labels |
Added:
?
|
In Joomla 4 we also see the Web AssetManager adding link tags (to add stylesheets) tha have a closing slash at the end of the tag. This is not 'HTML5 proof.'
closing as we have a pr to test
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2024-08-22 08:58:37 |
Closed_By | ⇒ | alikon | |
Labels |
Added:
Feature
Removed: ? |
Update: JCE editor creator Ryan pointed met at this code when I asked him about CSS files that were inlcuded by JCE:
https://github.com/joomla/joomla-cms/blob/4.2-dev/libraries/src/Document/Renderer/Html/StylesRenderer.php#L190
He said: "Stylesheets are rendered via the Joomla API, and this using self-closing tags regardless of the doctype."