<p>You can <code>cycle</code> your <code>loop.index0</code> property if you really need to add a class </p>

<pre><code>{{ cycle(['first', 'second', 'last'], loop.index0) }}
</code></pre>

<p>If the other elements don't need a class insert an empty value <code>''</code></p>

<p>You can as well check for a specific value of your <code>loop.index0</code></p>

<p>However if you just want to add certain style attributes you can use the <a href="https://css-tricks.com/how-nth-child-works/" rel="nofollow noreferrer">nth</a> selector </p>

CC BY-SA 4.0
2018-05-06T10:58:30.923Z
THAT worked like a charm!
THANKS!
PLAN42
CC BY-SA 4.0
2018-05-06T10:37:20.807Z
2018-05-06T10:37:20.807Z
Robin Schambach
<p>Trying to add entries in a visual array on my homepage.
Problem is that I need a special class on the last item in every row.<br>
<em>col_last</em></p>

<p>Trying to get my head around how to automate this, in order to avoid "special entries" for these. </p>

<p>Any ideas?</p>

<pre><code>{% for item in craft.entries.section('services').orderBy('postDate asc').all() %}
    &lt;div class="clear bottommargin-sm"&gt;&lt;/div&gt;
    &lt;div class="col_one_third *col_last*"&gt;
        &lt;div class="feature-box fbox-small fbox-plain" data-animate="fadeIn"&gt;
            &lt;div class="fbox-icon"&gt;
                &lt;a href="#"&gt;&lt;i class="icon-{{ item.serviceIcon }}"&gt;&lt;/i&gt;&lt;/a&gt;
            &lt;/div&gt;
            &lt;h3&gt;{{ item.title }}&lt;/h3&gt;
            &lt;p&gt;{{ item.serviceTagline }}&lt;/p&gt;
        &lt;/div&gt;
    &lt;/div&gt;
{% endfor %}
</code></pre>

CC BY-SA 4.0
2018-05-06T10:28:26.690Z
Do you really need a special class or just a special style (css)?
Robin Schambach
CC BY-SA 4.0
2018-05-06T10:37:11.337Z
Unfortunately I need to ADD a class, but I guess it pretty much the same procedure to single out every 3'rd item.
PLAN42
<templating>
Add style on every third entry
# Add style on every third entry

(Asked by: username_0 on 2018-05-06)

Trying to add entries in a visual array on my homepage.
Problem is that I need a special class on the last item in every row.
col_last
Trying to get my head around how to automate this, in order to avoid "special entries" for these. 
Any ideas?
{% for item in craft.entries.section('services').orderBy('postDate asc').all() %}
    
    
        
            
                
            
            {{ item.title }}
            {{ item.serviceTagline }}
        
    
{% endfor %}

**Tags:** templating

> **Comments:**
> **username_1**: Do you really need a special class or just a special style (css)?  
> **username_0**: Unfortunately I need to ADD a class, but I guess it pretty much the same procedure to single out every 3'rd item.  

---

## 1 answers

### Answer by username_1 on 2018-05-06. Score: 4 | Accepted answer

You can cycle your loop.index0 property if you really need to add a class 
{{ cycle(['first', 'second', 'last'], loop.index0) }}

If the other elements don't need a class insert an empty value ''
You can as well check for a specific value of your loop.index0
However if you just want to add certain style attributes you can use the nth selector

> **Comments:**
> **username_0**: THAT worked like a charm! THANKS!  

---

