What is a modal? And how to build a CSS-only Modal
CSS has come a long way from its humble beginnings of basic styling. Thanks to the use of pseudo-classes, we’re now able to style elements based on certain behaviour. In this tutorial, we’ll be using the :target pseudo-class to build a modal element.
What is a modal?
A modal is an element displayed on top of other elements on a webpage, preventing interaction with the rest of the webpage until the modal is dismissed. Modals are usually used to display information pertinent to the user or call attention to a required action.
Since modals require user interaction to be displayed or dismissed, they are commonly built using JavaScript. There’s even an inbuilt JavaScript API specifically for handling modals without needing to write any JavaScript code.
In this tutorial, however, we’ll be looking at how to build modals without the use of any JavaScript at all. Instead, we’ll build our fully functional modal CSS component.
The :target CSS pseudo-class represents a unique element (the target element) with an id matching the URL’s fragment. - MDN
CSS Modal Demo
Let’s take a look at what we’ll be building:

