HTML Validation
- 3 minutes to read
The ASPxHtmlEditor automatically validates HTML code contained in an HTML View. This editor can remove all potentially harmful code such as unknown tags and attributes, script elements, client-side event handlers, URLs with script content, etc. The resulting HTML code is safe, valid, and compliant with the specified document type (the HtmlEditorHtmlEditingSettings.AllowedDocumentType property): XHTML 1.0 Transitional, HTML5, or both.
Automatic validation also helps to keep HTML code valid by correcting invalid tag hierarchies and changing invalid attribute values.
Additionally, you can use the ASPxHtmlEditor.CorrectHtml method to correct the required HTML code.
The main actions performed during validation are listed below:
- Convert all tag names to lower case.
- Correct invalid tag overlap.
- Correct invalid tag nesting.
- Correct invalid attribute values.
- Correct invalid comment values.
- Remove unknown tags.
- Remove forbidden elements (ASP.NET directives, invalid processing instructions, etc.).
- Remove unknown attributes.
- Remove unrequired attributes with empty values.
- Remove the closing tag if it is prohibited by the element’s content model.
- Remove invalid attributes for the current element type.
Optionally remove tags and attributes of the following types:
- SCRIPT elements, client-side event handlers, and HREF attributes with script content (if the HtmlEditorHtmlEditingSettings.AllowScripts property is set to
false
) - IFRAME elements (if the HtmlEditorHtmlEditingSettings.AllowIFrames property is set to
false
) - AUDIO and VIDEO elements (if the HtmlEditorHtmlEditingSettings.AllowHTML5MediaElements property is set to
false
) - OBJECT and EMBED elements (if the HtmlEditorHtmlEditingSettings.AllowObjectAndEmbedElements property is set to
false
) - IFRAMES elements containing a link to YouTube video (if the HtmlEditorHtmlEditingSettings.AllowYouTubeVideoIFrames property is set to
false
) - All form elements such as FORM, INPUT, and SELECT (if the HtmlEditorHtmlEditingSettings.AllowFormElements property is set to
false
) - Style attributes (if the HtmlEditorHtmlEditingSettings.AllowStyleAttributes property is set to
false
) - ID attributes (if the HtmlEditorHtmlEditingSettings.AllowIdAttributes property is set to
false
)
- SCRIPT elements, client-side event handlers, and HREF attributes with script content (if the HtmlEditorHtmlEditingSettings.AllowScripts property is set to
- Close an element within its start tag if the element content model is empty.
- Insert required attributes that have been omitted, using their default values.
- Encode ampersands within the attribute value.
- Validate entity references and remove invalid references.
- Replace by-code entity references with their by-name equivalents, if possible.
- Replace deprecated elements (such as u, s, strike, font, center) found within the editor’s HTML markup with their valid variants (if the HtmlEditorHtmlEditingSettings.UpdateDeprecatedElements property is set to
true
). - Convert the b and i elements into the strong and em elements, respectively (if the HtmlEditorHtmlEditingSettings.UpdateBoldItalic property is set to
true
).
For more information about editor parameters that allow you to control validation settings, see the following topic: HTML validation parameters.