W3C Validation Space not allowed

Hi there,

I try to optimize my website. For this reason I checked the W3C HTML Validator. But there is one error I do not get rid of:

Illegal character in path segment: space is not allowed.

This is my html code:

<a href="/tag:MacBook pro" class="p-category">

So I use tags for taxonomy and of course some Tags do have spaces in there. So my question how can I avoid this error, but still use tags with spaces?



In order to validate, the HTML would be <a href="/tag:MacBook%20pro" class="p-category">

You could try changing your tag to MacBook%20pro but I think that is going to look weird on your page. In your theme, possibly in a file named “blog_item.html.twig”, look for this code:

  {% for tag in page.taxonomy.tag %}
    <a href="{{ blog.url|rtrim('/') }}/tag{{ config.system.param_sep }},{{ tag }}">{{ tag }}</a>
  {% endfor %}

and then change the a tag to:

<a href="{{ blog.url|rtrim('/') }}/tag{{ config.system.param_sep }},{{ tag|url_encode }}">{{ tag }}</a>

That should fix your validation issue while leaving the displayed tag as is.


Thank for your advice Ryan. Worked great! Thanks!