# How to Style Even/Odd Elements in CSS?

## Even/Odd styling using CSS

You can select and style even/odd elements using the `nth-child()` CSS pseudo-class in the following two ways:

## Using Keyword Values

You can use the `even` or `odd` keywords with `nth-child()` to select even/odd elements in a group of siblings like so:

```li:nth-child(even) {}
li:nth-child(odd) {}
```

This is the preferred way of doing this since it is more readable.

## Using Functional Notation

You can pass in the following arguments to `nth-child()` to select even/odd elements in a group of siblings:

```li:nth-child(2n) {} /* even */
li:nth-child(2n+1) {} /* odd */
```

Where:

• `n` represents non-negative integers starting from 0;
• The number before `n` represents the integer step size;
• The number followed by `+` symbol (as you can see with the selector for odd numbers) represents the integer offset number, which is optional.

Perhaps the following table would help you better visualize the way these selectors work:

n 2n 2n+1
`0` `0` [=(2 * 0)] `1` [=(2 * 0) + 1]
`1` `2` [=(2 * 1)] `3` [=(2 * 1) + 1]
`2` `4` [=(2 * 2)] `5` [=(2 * 2) + 1]
... ... ...

Please note that the matching of elements in a group of siblings starts from one. Therefore, the first matched element would be odd.

Hope you found this post useful. It was published . Please show your love and support by sharing this post.
{"ft_lang_label":"__label__en","ft_lang_prob":0.81511635,"math_prob":0.642404,"size":1276,"snap":"2022-40-2023-06","text_gpt3_token_len":351,"char_repetition_ratio":0.1273585,"word_repetition_ratio":0.05652174,"special_character_ratio":0.31034482,"punctuation_ratio":0.11462451,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9606943,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-10-05T03:23:20Z\",\"WARC-Record-ID\":\"<urn:uuid:482a3809-c367-45f2-9fa2-01c13d9cf9ce>\",\"Content-Length\":\"361117\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:2b3fc0e1-7ae1-44e2-a367-6c3b5aa3ad1f>\",\"WARC-Concurrent-To\":\"<urn:uuid:02c8ea5f-4b65-4c38-a891-3143b7ea096f>\",\"WARC-IP-Address\":\"172.67.176.28\",\"WARC-Target-URI\":\"https://www.designcise.com/web/tutorial/how-to-style-even-or-odd-elements-in-css\",\"WARC-Payload-Digest\":\"sha1:KZ2APDA3JTDH2RNXOFC3ATIUFQB5L7QZ\",\"WARC-Block-Digest\":\"sha1:33O4PLANZREOCCPXZUL4EJYXYZS3FEUU\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-40/CC-MAIN-2022-40_segments_1664030337531.3_warc_CC-MAIN-20221005011205-20221005041205-00194.warc.gz\"}"}