Advanced Search Usage Terms Submit Contact
Dynamic Drive CSS Library

CSS Library: Other: Here

Pure CSS Modal Window

Author: Dynamic Drive

CSS's: :target pseudo class is one of those underused features of CSS with lots of exciting potential applications. It is triggered when the page's URL fragment (#myelement) matches an element's ID; in other words, when the user jumps to a specific element on the page.

Using the :target pseudo class, the following shows how to create pure CSS Modal Windows that are triggered when the user clicks on an HTML anchor link. Look Mah no JavaScript! The modal can easily be dismissed by creating another HTML anchor that points to a non existent or different element on the page.

Browser compatibility wise, the :target pseudo class is well supported in modern browsers, including IE9+. In lesser browsers, the modal windows simply won't be shown.

Demo:

Simple Modal Modal Dialog
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec felis enim, placerat id eleifend eu, semper vel sem. Close Modal

CSS Only Modal ×

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec felis enim, placerat id eleifend eu, semper vel sem.

The CSS:

The HTML:

Code Info

Rate this code:

Date Posted: 05/28/2017

Revision History: None

Usage Terms: Click here

Your Comments
Copyright 2006-2016 Dynamic Drive