Kentico().PageDescription() meta tags fail kentico HTML validation

James de Boer asked on April 30, 2025 18:50

On pages with the Description meta tag created using @Html.Kentico().PageDescription() helper from https://docs.kentico.com/13/developing-websites/retrieving-content/displaying-page-content

The meta tag has a closing and generates the following info message when using the kentico HTML validation in the Admin site.

"Trailing slash on void elements has no effect and interacts badly with unquoted attribute values."

This is not really a problem but it would be nice if there was a way to get the HTML validation completely clean. Is there any way of interacting with the @Html.Kentico().PageDescription() helper to stop it putting the closing tag in?

Tag created looks like this

< meta content="Blah blah blah" name="description" />

Recent Answers


Rahul Kumawat answered on May 5, 2025 18:19

To address the issue with the meta tag generated by @Html.Kentico().PageDescription() helper in Kentico, the challenge lies in the HTML validation warning about the trailing slash on void elements (like tags). Currently, this helper method seems to automatically include a closing slash, which is not necessary and triggers the validation message.

Here is a approach you could consider to resolve this: Custom Helper Method: Instead of using @Html.Kentico().PageDescription(), create a custom helper method or directly output the meta tag using Razor syntax without the helper. Here’s an example of how you can achieve this:

In this approach, you would set ViewBag.PageDescription in your controller or view model, ensuring it contains the correct description content dynamically.

0 votesVote for this answer Mark as a Correct answer

James de Boer answered on May 6, 2025 12:26

Hi thanks for your answer. I did directly output the met tag in the Razor in the end.

    <meta name="description" content="@currentPageContext.Metadata.Description">

where currentPageContext comes from

@inject IPageDataContextRetriever pageDataContext
pageDataContext.TryRetrieve<TreeNode>(out currentPageContext);

This seems to work.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.