Back to CSS Notes
Topic #85

Structural

Structural pseudo-classes select elements by position, like nth-child and first-of-type. They power zebra stripes and layout patterns.


Structural Pseudo-classes

Structural pseudo-classes select elements based on their position in the document tree.


The CSS :first-child Pseudo-class

The :first-child pseudo-class matches a specific element that is the first child of another element.

Style all first child

elements

In the following example, the selector matches all

elements that is the first child of any element:

Example

p:first-child
{

color: blue;

}

Style the first element in all

elements

In the following example, the selector matches the first element in all

elements:

Example

p em:first-child
{

color: blue;

}

Style all elements in all first child

elements

In the following example, the selector matches all elements in

elements that are the first child of another element:

Example

p:first-child em
{

  color: blue;

}

The CSS :lang() Pseudo-class

The :lang() pseudo-class is used to select elements with a lang attribute with the specified value.

Example

<html>

<head>

<style>

  q:lang(no) {
  quotes: "~" "~";
}

</style>

</head>

<body>

<p>Some text <q lang="no">A quote in a paragraph</q>
Some text.</p>

</body>

</html>

Other Structural Pseudo-classes

There are many more structural pseudo-classes available:

  • :last-child - Matches the last child of a parent
  • :nth-child(n) - Matches the nth child of a parent
  • :nth-last-child(n) - Matches the nth child from the end
  • :only-child - Matches an element that is the only child
  • :first-of-type - Matches the first element of its type
  • :last-of-type - Matches the last element of its type

CSS Pseudo-classes Reference

Note: For a complete list of all CSS Pseudo-classes, visit our CSS Pseudo-classes Reference.

Want to go beyond the notes?

Join Coding Now Tech Institute's CSS course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Structural – FAQs

Quick answers about learning Structural in CSS.

This free note from Coding Now Tech Institute explains Structural in CSS — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every CSS topic on Coding Now Tech Institute, including Structural, is 100% free with no signup required.
With focused practice, most students grasp Structural in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.