CSS element Selector Last Updated : 29 Aug, 2024 Comments Improve Suggest changes Like Article Like Report The element selector in CSS is used to select HTML elements that are required to be styled. In a selector declaration, there is the name of the HTML element and the CSS properties which are to be applied to that element is written inside the brackets {}. Syntax:element { \\ CSS property}Example 1: This example shows the element selector in CSS. html <!DOCTYPE html> <html> <head> <title>element selector</title> <style> /* h1 element selected here */ h1 { color: green; text-align: center; } /* h2 element selected here */ h2 { text-align: center; } </style> </head> <body> <h1>GeeksforGeeks</h1> <h2>element Selector</h2> </body> </html> Output: Example 2: This example shows the element selector in CSS. html <!DOCTYPE html> <html> <head> <title>element selector</title> <style> h1 { text-align: center; } h2 { text-align: center; color: green; font: bolder cursive; } form { text-align: center; } </style> </head> <body> <h1>FORM</h1> <h2>Please fill in details:</h2> <form action="#"> Name: <input type="text" value="name"><br> Age: <input type="text" value="age"><br> City: <input type="text" value="City"><br> </form> </body> </html> Output: Supported Browsers: The browser supported by element selectors are listed below:Google ChromeInternet ExplorerFirefoxSafariOpera Comment More infoAdvertise with us S shivangsharma15 Follow Improve Article Tags : Web Technologies CSS CSS-Selectors Similar Reads CSS [attribute*=value] Selector The [attribute*="str"] selector targets the elements whose attribute values contain a specified substring. This substring can appear anywhere within the attribute's value â beginning, end, or middle.Syntax:element [attribute*="str"] { // CSS Property} Example: In the following example, the <p> 2 min read CSS :nth-last-of-type() Selector The:nth-last-of-type() Selector in CSS is used to style only those elements which are the nth number of child of the parent element. The selector counts from the last-child element. A n could be a number, a keyword, or a formula. Syntax::nth-last-of-type(number) { //css Property;} Where number is th 3 min read CSS [attribute$=value] Selector The [attribute$=âvalueâ] selector is used to select those elements whose attribute value ends with a specified value "value". The value need not to be present as separate word. It may be a part of another word or expression but it needs to be present at the end. Syntax:[attribute$="value"] { // CSS 2 min read CSS :nth-of-type() Selector The :nth-of-type() in css Selector is used to style only those elements which are the nth number of child of its parent element. An n may be a number, a keyword, or a formula. Syntax::nth-of-type(number) { // CSS Property;} Where number is the argument that represents the pattern for matching elemen 2 min read CSS :nth-last-child() Selector The nth-last-child() selector in CSS is used for selecting elements based on their position among sibling elements, but starting the count from the end rather than the beginning. This selector is particularly useful for styling elements dynamically based on their order in reverse, allowing for flexi 3 min read CSS :nth-child() Selector The :nth-child() pseudo-class selector targets elements based on their position among siblings, making it ideal for dynamic styling. It can select elements using specific positions (e.g., first, odd, or even), or patterns like An+B. This flexible CSS tool improves web design by simplifying how you a 3 min read CSS ::first-line Selector The ::first-line selector in CSS is used to apply style to the first line of a block-level element. The length of the first line depends on many factors, including the width of the element, the width of the document, font-size of the text, etc. Syntax:::first-line { //CSS Property}Example: html < 2 min read CSS :not Selector The :not(selector) selector is used to style every element that is not specified by the given selector. Known as the negation pseudo-class, it allows developers to exclude specific items from being selected.Syntax::not(selector) { //CSS Property}Usage ExamplesExample 1This example demonstrates the u 2 min read CSS ::first-letter Selector The ::first-letter selector CSS Pseudo-element is used to apply the style to the first letter of the first line of a block-level element, the condition is it should not be preceded by other content ( such as images or inline tables).Syntax: ::first-letter { // CSS Property}Accepted Properties:backgr 2 min read CSS :indeterminate Selector The :indeterminate selector in CSS is used to select any form elements that are in indeterminate state i.e a state that is neither checked nor unchecked. Elements targeted by this selector are:<input = "checkbox"> elements whose indeterminate property is set to true by JavaScript<input = "r 2 min read Like