Skip to main content
codingCourses
  • HTML
  • CSS
  • JavaScript
  • PHP
  • CSS Tutorial
  • CSS Selectors
  • CSS Properties
  • Practical Tips
CSS
  • CSS Tutorial
  • Color Picker
    Pick a Color and Get its Code
  • Web Color Codes
    Color Palette for HTML and CSS
  • CSS Color Names
    Color Keywords for Web Design
  • rem and em Units
    Relative Length Units for Font Size
  • CSS Specificity
    Selector Order, Rules, and Cheat Sheet
  • !important Keyword
    Overriding Style Priority
  • CSS Variables
    How to Use Custom Properties in CSS
CSS Selectors
  • CSS Selector Reference
  • :first-child
    Select the First Child
  • :last-child
    Select the Last Child
  • :nth-child(n)
    Select the nth child
  • :nth-last-child(n)
    Select the nth Child Element from the End
  • :nth-of-type(n)
    Select the nth Child of the Same Tag
  • :nth-last-of-type(n)
    Select the nth-to-last Child of the Same Tag
  • :first-of-type
    Select the First Child of the Same Tag
  • :last-of-type
    Select the Last Child of the Same Tag
  • :only-of-type
    Select the Only Child of Its Tag Name
  • :focus-within
    Matches Focused Elements or Descendants
  • ::before
    Before Pseudo-Element Selector
  • ::after
    After Pseudo-Element Selector
  • ::marker
    Select Automatically Generated List Markers
  • ::placeholder
    Styling Placeholder Text
CSS Properties
  • CSS Property Reference
  • aspect-ratio
    Sets an Element's Width-to-Height Ratio
  • background-clip
    Specifying the Background Painting Area
  • background-origin
    Specifies the Background Positioning Area
  • box-shadow
    Applying Shadow Effects to Element Boxes
  • box-sizing
    Defines the Element's Sizing Calculation Model
  • caret-color
    Change Caret Color
  • content
    Specify Pseudo-Element Content
  • line-height
    Setting Line Spacing for Text
  • object-fit
    How to Fit Images and Videos Perfectly
  • object-position
    Positioning with object-fit
  • pointer-events
    Controlling Pointer Interactions
  • text-align
    Setting Horizontal Alignment for Text
  • text-decoration
    Shorthand for Text Decoration Styling
  • text-decoration-line
    Specifies Line Decoration Types
  • text-decoration-color
    Specifies the Color of Decorations
  • text-decoration-style
    Specifies the Line Style of Text Decorations
  • text-decoration-thickness
    Specifies the Thickness of Decorations
  • Underline Position and Offset Properties
    Setting Underline Position and Spacing
  • text-underline-position
    Specifies the Positional Basis of Underlines
  • text-underline-offset
    Adjusting Underline Offset
  • text-emphasis
    Shorthand for Text Emphasis Marks
  • text-emphasis-style
    Specifies the Shape of Emphasis Marks
  • text-emphasis-color
    Specifies the Color of Emphasis Marks
  • text-emphasis-position
    Specifies the Position of Emphasis Marks
  • text-overflow
    Setting a Single-Line Text Ellipsis (...)
  • text-shadow
    Applying Shadow Effects to Text
  • vertical-align
    Vertical Alignment: Inline Tags & Table-Cells
  • white-space
    Specifies White Space and Soft Wrapping
  • will-change
    A Hint for Rendering Optimization
  • word-break
    Rules for Breaking Words When Text Wraps
  • writing-mode
    Setting Text in Vertical Writing Mode
  • -webkit-line-clamp
    Setting a Multi-Line Text Ellipsis (…)
  • -webkit-text-stroke
    Styling the Stroke of Text
  • -webkit-text-stroke-color
    Specifies the Stroke Color of Text
  • -webkit-text-stroke-width
    Specifies the Stroke Width of Text
CSS Practical Tips
  • Practical Tip Reference
  • Centering with CSS - Text
    Centering Text Made Easy
  • Centering with CSS - Images
    Centering Images Made Easy
  • Centering with CSS - Elements
    Centering Elements Made Easy
  • List Marker Styling
    Examples and Customization Techniques
  • <details> Tag Styling
    Learn how to apply custom styles to <details>
  • Scrollbar Customization
    Overview of CSS Scrollbars

CSS Selector Reference

CSS Next

CSS selectors are patterns used to select elements and apply styles in CSS (Cascading Style Sheets). They offer various methods for targeting elements with precision.

CSS Selector Reference
:first-child
Select the First Child
The :first-child pseudo-class selects the element that is the first child of its parent. It works the same as the :nth-child(1).
:last-child
Select the Last Child
The :last-child pseudo-class selects the element that is the last child of its parent. It works the same as the :nth-last-child(1).
:nth-child(n)
Select the nth child
The :nth-child(n) pseudo-class selects the element that is the nth child of its parent. For example, :nth-child(2) selects the second child element.
:nth-last-child(n)
Select the nth Child Element from the End
The :nth-last-child(n) pseudo-class selector selects an element that is the nth child of its parent, counting from the end. For example, :nth-last-child(2) selects the second child element when counting backward from the last child.
:nth-of-type(n)
Select the nth Child of the Same Tag
The :nth-of-type(n) pseudo-class selects the element that is the nth sibling of the same tag type. For example, p:nth-of-type(2) selects the second <p> element among only the <p> elements that share the same parent.
:nth-last-of-type(n)
Select the nth-to-last Child of the Same Tag
The :nth-last-of-type(n) pseudo-class selector selects the nth element from the end among siblings of the same tag name.
:first-of-type
Select the First Child of the Same Tag
The :first-of-type pseudo-class selects the element that is the first sibling of the same tag type. For example, p:first-of-type selects the first <p> element among only the <p> elements that share the same parent.
:last-of-type
Select the Last Child of the Same Tag
The :last-of-type pseudo-class selects the element that is the last sibling of the same tag type. For example, p:last-of-type selects the last <p> element among only the <p> elements that share the same parent.
:only-of-type
Select the Only Child of Its Tag Name
The :only-of-type pseudo-class selector selects an element that is the only one of its tag type (tag name) among its sibling elements. In other words, it matches an element that is both the first and the last of its kind within the same parent.
:focus-within
Matches Focused Elements or Descendants
The :focus-within pseudo-class selects an element when it, or any of its descendants, has focus.
::before
Before Pseudo-Element Selector
The ::before pseudo-element selector generates a child pseudo-element directly before the selected element's actual content, acting as its first child, and allows it to be styled.
::after
After Pseudo-Element Selector
The ::after pseudo-element selector generates a child pseudo-element directly after the selected element’s actual content, acting as its last child, and allows it to be styled.
::marker
Select Automatically Generated List Markers
The ::marker pseudo-element selector selects the list markers automatically generated for elements whose display property is set to list-item, such as li and summary elements.
::placeholder
Styling Placeholder Text
The ::placeholder pseudo-element selector is used to style the placeholder text of HTML text input controls, allowing customization of size, color, horizontal alignment, and more.
CSS Next

codingCourses offers coding tutorials made for everyone.
All materials and examples are continuously reviewed to prevent errors; however, complete accuracy cannot be guaranteed.
Therefore, please carefully test and review all materials and examples to ensure they are free of errors, bugs, or vulnerabilities before relying on them.
They are available under the Creative Commons Attribution 4.0 International

Copyright © codingCourses. All Rights Reserved.