li:nth-child(3n) {
background-color: red;
li:nth-child(4n) {
background-color: blue;
li:nth-child(5n) {
background-color: green;
CSS nth-3n is a property that allows you to specify the third iteration of a specific CSS class. It is useful when you want to apply a set of rules to a specific element in a sequence, such as in a loop or a repeating pattern.
The syntax for using CSS nth-3n is as follows:
“`css
element:nth-child(3n) {
/* CSS rules for the 3rd iteration of the element */
Here, `element` is the name of the element you want to apply the rules to. The `3n` refers to thenth-child(3), which means the 3rd iteration of the specified class.
By default, the `nth-child` property selects the 1st, 2nd, 4th, and 5th iteration of a class, but it can be changed to select any other iteration by using the `3n` syntax.
For example, if you want to select the 3rd, 4th, and 5th iteration of a class on the first, second, and third elements in a loop, you can use the following code:
“`css
HTML
- Item 1
- Item 2
- Item 3
- Item 4
CSS
li:nth-child(3n) {
background-color: red;
li:nth-child(4n) {
background-color: blue;
li:nth-child(5n) {
background-color: green;
In this example, the first element will have a red background color, the second element will have a blue background color, the third element will have a green background color, and the fourth element will have a red background color.
Overall, CSS nth-3n is a useful property that allows you to specify the third iteration of a specific CSS class and apply rules to specific elements in a sequence.