Feature No Code Attached Yet
avatar jjnxpct
jjnxpct
28 Sep 2022

Problem identified

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.

Proposed solution

For the $doc->addHeadLink the output should then be changed to omit the closing tag.

Open questions

Should Joomla (4) be able to output sel-closing tags that are HTML5 proof? Eventhought it does not cauze any issues at the moment?

avatar jjnxpct jjnxpct - open - 28 Sep 2022
avatar joomla-cms-bot joomla-cms-bot - change - 28 Sep 2022
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 28 Sep 2022
avatar jjnxpct
jjnxpct - comment - 28 Sep 2022

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."

avatar itmagpro
itmagpro - comment - 6 Oct 2022

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?

avatar jjnxpct
jjnxpct - comment - 2 Nov 2022

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.

avatar jjnxpct
jjnxpct - comment - 2 Nov 2022

Also I think Joomla 3 will not be changed with regards to this issue. But maybe J4 will.

avatar chmst chmst - change - 2 Nov 2022
Labels Added: ?
avatar chmst chmst - labeled - 2 Nov 2022
avatar jjnxpct
jjnxpct - comment - 25 Aug 2023

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.'

avatar brianteeman
brianteeman - comment - 22 Aug 2024

please test #43961

avatar alikon alikon - close - 22 Aug 2024
avatar alikon
alikon - comment - 22 Aug 2024

closing as we have a pr to test

avatar alikon alikon - change - 22 Aug 2024
Status New Closed
Closed_Date 0000-00-00 00:00:00 2024-08-22 08:58:37
Closed_By alikon
Labels Added: Feature
Removed: ?

Add a Comment

Login with GitHub to post a comment