DEV Community

Cover image for Creating Modal Windows with Pure CSS: No JavaScript Required

Creating Modal Windows with Pure CSS: No JavaScript Required

Max Prilutskiy on May 17, 2025

Wait, you can build modal windows without JavaScript? Yep, that's CSS secretly laughing at JavaScript behind its back. At Lingo.dev, we love diving...
Collapse
 
xwero profile image
david duymelinck

I find it a bit strange that nobody mentioned the dialog html element.
It is better than using a div and it has javascript events.

If you are feeling adventurous the CSS tricks from this post can be used. Personally I would stick to the small amount of javascript you need to add to make the dialog working.

Collapse
 
jesterly profile image
jesterly

Zero JS code is required if you use the Popover API with dialog element.

Collapse
 
xwero profile image
david duymelinck

Thank you for sharing that, I didn't know it existed. From MDN I see it is an experimental feature.

Thread Thread
 
jesterly profile image
jesterly

You're welcome. It's only experimental if you use hint popovers:

developer.mozilla.org/en-US/docs/W...

Collapse
 
maxprilutskiy profile image
Max Prilutskiy

If you are feeling adventurous the CSS tricks from this post can be used

Haha, yes, exactly!

We personally do use these tricks internally, but most of the time, from what we see, it's a design system / component library implementation detail.

Collapse
 
anitaolsen profile image
Anita Olsen

This is just brilliant! Thank you for sharing with us! ✨

Collapse
 
maxprilutskiy profile image
Max Prilutskiy

Thanks Anita :)

Collapse
 
jswhisperer profile image
Greg, The JavaScript Whisperer • Edited

Neat solution, I thought I'd fork your solution and demo a no js needed no css needed solution 🀯

I kid you not! I added CSS just to match your example, but it's not needed, and go for it disable js... still works github

Read more here: dev.to/jswhisperer/invoker-command...

it's also hella accessible!

Collapse
 
maxprilutskiy profile image
Max Prilutskiy • Edited

nice! πŸ”₯

Collapse
 
anthonymax profile image
Anthony Max

Great article!

Collapse
 
maxprilutskiy profile image
Max Prilutskiy

Thanks Anthony!

Collapse
 
nathan_tarbert profile image
Nathan Tarbert

pretty cool you can ditch js for stuff like this - honestly makes me wonder if i’m over-complicating my own setups. you think pushing css like this actually makes sites easier to maintain in the long run or nah?

Collapse
 
maxprilutskiy profile image
Max Prilutskiy

Great question Nathan!

I think it boils down to how well this type of CSS is encapsulated in the code in the end.

I personally think CSS modals are elegant, though it isn't the most usual thing to do. :)

Collapse
 
nevodavid profile image
Nevo David

Pretty cool seeing CSS pushed like this. Makes me want to mess around and see what else I can pull off without JS.

Collapse
 
ryanguitar profile image
Ryan Els

Excellent article and well explained πŸ˜πŸ‘πŸ»

From now on I won't make a modal any other way.

Collapse
 
maxprilutskiy profile image
Max Prilutskiy

⚑⚑

Collapse
 
lovit_js profile image
Lovit

Really loved how you explained both the :target method and the checkbox hack β€” super clear and practical. It’s amazing how much we can do with just CSS!

Collapse
 
maxprilutskiy profile image
Max Prilutskiy

CSS is becoming a programming language πŸ˜…

Collapse
 
veronica_prilutskaya_c597 profile image
Veronica Prilutskaya

Cool CSS trick!

Collapse
 
maxprilutskiy profile image
Max Prilutskiy

Yes, indeed!

Collapse
 
nevodavid profile image
Nevo David

pretty cool seeing css pull this off - makes me want to rethink some of my usual stacks haha. you ever find yourself secretly hoping to kick more js out of your projects?

Collapse
 
techcake_cloud_303ba945a4 profile image
techcake cloud

Discover the Top Rated DevOps Course in Kannur with Guaranteed Placement – Only at TechCake

Are you searching for the best DevOps course in Kannur? Whether you're a fresher aiming to start your tech career or a professional looking to upskill, TechCake offers the top-rated DevOps course in Kannur, designed to equip you with the skills companies are hiring for.

Why DevOps?
DevOps has rapidly become one of the most in-demand skillsets in the IT industry. Combining development and operations, it enables faster software releases, improved team collaboration, and more stable systems. As more companies adopt DevOps practices, the demand for certified DevOps professionals has skyrocketed.

TechCake – The Best DevOps Training Institute in Kannur
At TechCake, we don’t just teach DevOps β€” we make you job-ready. As a leading DevOps training institute in Kannur, our curriculum is tailored to current industry standards, and our trainers are certified experts with real-world experience.

Here’s what makes TechCake the preferred choice:

βœ… Hands-on training with real-time projects

βœ… Certified and experienced instructors

βœ… Resume-building and mock interview sessions

βœ… Weekend and weekday batch flexibility

βœ… Access to DevOps tools like Jenkins, Docker, Kubernetes, Git, Ansible, and AWS

What You’ll Learn in Our DevOps Course in Kannur
Our DevOps course covers a full stack of modern DevOps tools and practices. Some of the key modules include:

Introduction to DevOps & its lifecycle

Source code management with Git

Continuous integration with Jenkins

Containerization using Docker

Configuration management with Ansible

Orchestration with Kubernetes

Cloud deployment using AWS

Monitoring and logging tools

This structured approach ensures that you become a certified DevOps engineer, ready to work on real-world problems.

DevOps Course with Placement in Kannur – 100% Assistance
At TechCake, we understand that learning is only part of the journey β€” getting a job is the goal. That’s why we offer a DevOps course with placement in Kannur, with active support through:

Resume reviews & optimization

Mock interviews with real-time scenarios

HR and recruiter connections

Internship opportunities for freshers

Many of our alumni are now placed in top IT companies across India and abroad.