Is the head tag in Kentico valid when it is generated with the additional attribute?

   —   
We have received a very interesting question from one of our customers when the validity of pages generated by Kentico has been questioned because of the added attribute id=”head” to the <head> tag.  The use of ID attribute with any HTML element is pretty common, especially when it comes to more complex websites, CMS, CRM and other similar systems which are generating the code and allows you a modifications based on the ID attributes.

You can also check the pages are valid on your own using the W3C validator:  validator.w3.org/check

E.g. on this simple example code where the ID attribute is used and the code is valid:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="head"><title> Corporate site - Home </title> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> </head> <body> test </body> </html>


More detailed information could be found on the following page: www.w3schools.com/tags/att_global_id.asp
in combination with the code of Kentico and the DOCTYPE: www.w3schools.com/tags/tag_doctype.asp

"In HTML5, the id attribute can be used on any HTML element (it will validate on any HTML element. However, it is not necessarily useful)."

As you can see, this attribute is not allowed/valid only in the very old HTML4 definition, while in the Kentico we are using XHTML or HTML5.

So if you will open the PortalTemplate.aspx file, you will find out that the ID element is required here because it is an element generated on the server’s side where the ID attribute must be defined.

On the other hand, if you are willing to hide this attribute, so it will not be visible in the code of generated pages, you can achieve this by a simple modification:

Open the file: ~\CMSPages\PortalTemplate.aspx.cs
and in the method: protected override void OnPreRender(EventArgs e)

around line 33 add the following line of code:
this.head.ID = null;
 
Share this article on   LinkedIn

Martin Danko

Let me guide you on your journey of success. I will show you how to optimize your content production with Kentico Draft. Check out www.kenticocloud.com