CSS Basic Tutorial
CSS Flexbox
CSS selectors are patterns used to select and apply styles to HTML elements. They define which elements the style rules will affect. Selectors can be simple (like targeting an element directly) or more complex (targeting based on attributes, classes, or relationships between elements).
Targets all instances of a specified HTML element.
Targets elements with a specific class attribute. It is prefixed with a dot (.
).
Try it yourself
Targets an element with a specific id
attribute. It is prefixed with a hash (#
).
Try it yourself
Targets all elements on the page. It is denoted by an asterisk (*
).
Targets elements based on their attributes.
Try it yourself
>
)+
)~
)Targets elements that are descendants (children, grandchildren, etc.) of a specific parent element.
>
):Targets elements that are direct children of a specified element.
Try it yourself
+
):Targets an element that is immediately adjacent to a specified element.
Try it yourself
~
): Targets all siblings of a specified element.
Try it yourself
Targets elements based on their state or position (like hover
, first-child
, etc.).
Try it yourself
Targets and styles specific parts of an element, like the first letter or first line.
Try it yourself
Apply the same style to multiple elements by separating them with a comma.