Developer Corner - Invalid attribute name

19 Oct 2020 | Developer Corner

Helen Grimbly
  • Tweet this item
  • share this item on Linkedin

This week, Support Lead, Helen Grimbly explains what is meant by the Sitemorse Code Quality diagnostic file/html/badattr

Diagnostic: file/html/badattr: Invalid attribute name

This is a Sitemorse Code Quality error that is raised when an invalid attribute is set for an element. Please note that the DOCTYPE of an HTML document will determine which HTML specification we will compare your HTML against, and therefore which attributes can be applied to which elements. Please see the following document about DOCTYPEs: https://sitemorse.com/blog-article/9472/week-25-technical-service-bulletin-defining-doctype-webpage/

An example of the diagnostic 'file/html/badattr: Invalid attribute name' is as follows:

Example: 'frameborder' is not a valid attribute for tag 'iframe'

The attribute frameborder is not a valid attribute for the element iframe, and this may not work in different browsers as intended (frameborder was a valid attribute under HTML 4, but in HTML 5 it has been removed).

<iframe width="560" height="315" src="https://www.example.com/" frameborder="0"></iframe>

The correct way to implement this is to set the frameborder using CSS style sheets:

<iframe class="myiframe" width="560" height="315" src="https://www.example.com/"></iframe>

And in your CSS add:

.myiframe { 
  border: none; 
}

This Code Quality error will affect the Sitemorse score.