How to use a not:first-child Selector in CSS? Last Updated : 09 Oct, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report The :not(:first-child) selector in CSS targets all elements that are not the first child within their parent. It allows you to style elements except the first one, making it useful for applying styles to subsequent items in a list or layout.Syntax:not( element ) { // CSS property } Example: In this example, we are using the not:first-child selector to select the non-first child from the parent element. It contains <ul> Tag so it selects all child elements of <div> tag except its first child. HTML <!DOCTYPE html> <html> <head> <title>not first child selector</title> <style> h1 { color: green; } div ul:not(:first-child) { background-color: green; color: white; font-style: italic; font-weight: bold; width: 60%; margin-left: 100px; } h1, h2 { text-align: center; } </style> </head> <body> <h1>GeeksforGeeks</h1> <h2>not:first-child selector </h2> <div> <ul style="margin-left:100px"> <li>gfg</li> <li>geeks</li> <li>sudo</li> </ul> <ul> <li>Bca</li> <li>Mca</li> <li>B.Tech</li> </ul> </div> </body> </html> OutputUse a not:first-child Selector in CSS - FAQsCan :not(:first-child) be combined with other selectors in CSS?Discusses combining :not(:first-child) with other selectors to target specific elements in complex scenarios.How do I style every list item except the first using :not(:first-child)?Provides examples for styling list items while excluding the first one.Can :not(:first-child) be used with pseudo-elements like ::before or ::after?Explores the use of :not(:first-child) in combination with pseudo-elements for advanced styling. Comment More infoAdvertise with us Next Article What is the difference between display: inline and display: inline-block in CSS? M manaschhabra2 Follow Improve Article Tags : Web Technologies CSS CSS-Questions Similar Reads 6 Best CSS frameworks You should Know to design Attractive Websites If you want to speed up your website and development process, or want to add some classy designs to your website, then you're at the right place. Awesome new popups, speed, ultimate colors and themes are waiting for you. Front end development is the complete pack of creation and colors and have amaz 3 min read Space between two rows in a table using CSS The space between two rows in a table can be done using CSS border-spacing and border-collapse properties. The border-spacing property is used to set the spaces between cells of a table and border-collapse property is used to specify whether the border of the table is collapsed or not. The border-sp 1 min read What is the difference between display: inline and display: inline-block in CSS? The display property in CSS is a very useful and commonly used property that contains many values. The display property defines how an HTML element should be displayed on the webpage. The property also specifies the type of box used for an HTML element and how it should be laid out on the page. If w 4 min read How to Write a:hover in Inline CSS? The :hover pseudo-selector in CSS enables you to modify the style of elements when a user hovers their mouse over them. This selector is widely used to improve user experience by adding visual feedback on elements like buttons, links, images, or any interactive items on a webpage. For the :hover eff 2 min read How to place two div side-by-side of the same height using CSS? The two or more different div of same height can be put side-by-side using CSS. Use CSS property to set the height and width of div and use display property to place div in side-by-side format. The used display property are listed below: display:table; This property is used for elements (div) which 2 min read What is a clearfix? A clearfix is a way for an element to automatically clear or fix its elements so that it does not need to add additional markup. It is generally used in float layouts where elements are floated to be stacked horizontally. If the element is taller than the element containing it then use the overflow 3 min read Making a div Vertically Scrollable using CSS The overflow property in CSS controls how content that goes beyond an element's boundaries is handled. It can either hide the extra content or add scrollbars so users can scroll to see more without leaving the current view. This helps display large amounts of content, such as text, images, or tables 3 min read How to give a div tag 100% height of the browser window using CSS CSS allows to adjustment of the height of an element using the height property. While there are several units to specify the height of an element. Set the height of a <div> to 100% of its parent container with height: 100%, or use height: 100vh; for a full viewport height, ensuring the <div 3 min read Wildcard Selectors (*, ^ and $) in CSS for classes Wildcard selectors can be used with attribute selectors. The asterisk (*) matches any character, the caret (^) matches the start, and the dollar sign ($) matches the end of an attribute value. For example, .class* selects all elements with a class attribute containing "class" anywhere, .class^ selec 3 min read How to style a dropdown using CSS? We will learn how to style the dropdown list using CSS and explore its implementation through examples. Dropdown menus are commonly used to allow users to select an option from a predefined list. Styling them properly can enhance your website's user experience and visual appeal.What is a <select 3 min read Like