Insert html in views every nth element I want to insert &lt;div class="clearfix"&gt;&lt;/div&gt; every nth element. How can I insert this into the twig template of a view?

Same Question for D7: Insert *whatever* every nth row in Views
In twig you can use |batch().

For example to group the view in groups of 5 and add a div container around each group:

views-view-unformatted.html.twig

{% for group in rows|batch(5) %}
  &lt;div class="group"&gt;
  {% for row in group %}
    &lt;div{{ row.attributes }}&gt;
      {{ row.content }}
    &lt;/div&gt;
  {% endfor %}
  &lt;/div&gt;
{% endfor %}