Yogesh Chauhan's Blog

The :last-of-type selector

in CSS on September 23, 2020

The :last-of-type selects the element that is the last child, of a particular type, of its parent.

For e.g., in the code below the css selects the last paragraph and the last heading h2.

<!DOCTYPE html>
p:last-of-type {
 background: #C5CAE9;

h2:last-of-type {
 background: #CDDC39;


<div class="container">
 <p>1st paragraph</p>
 <p>2bd paragraph</p>
 <p>last paragraph</p>
 <h1>1st Heading</h1>
 <h2>1st heading</h2>
 <h2>last heading</h2>



Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to add Read More Read Less Button using JavaScript? #3 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #4 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #5 How to uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
Learn to make a responsive gallery using CSS Grid and without media queriesCSSHow to create a full screen loader using CSS and JavaScript?CSSHow to concatenate variable with string in Swift?SwiftHow can one check to see if a remote file exists using PHP?PHPNATURAL JOIN in PostgresPostgresUnderstanding the confusing and handy “This” keyword in JavaScriptJavaScriptWhat does JSX do in React?ReactDynamically generate names in SCSS (animation example)SCSSEffects in ReactReactKilling A Project Part 1: What criteria should be used to cancel/kill a project?MiscellaneousHow to import MySQL small sample database into phpMySQL?SQL/MySQLSQL Right JoinSQL/MySQL