Like ’em or loath ’em, whether or not you’re displaying an alert, a message, or a publication signup, dialogue containers draw consideration to a selected piece of content material with out sending somebody to a unique web page. Prior to now, dialogues relied on a mixture of divisions, ARIA, and JavaScript. However the HTML dialog
ingredient has made them extra accessible and style-able in numerous methods.
So, how are you going to take dialogue field design past the generic look of frameworks and templates? How are you going to model them to mirror a model’s visible identification and assist to inform its tales? Right here’s how I do it in CSS utilizing ::backdrop
, backdrop-filter
, and animations.

I discussed earlier than that Emmy-award-winning recreation composer Mike Price employed me to create a extremely graphical design. Mike loves ’90s animation, and he challenged me to search out methods to include its retro model with out making a pastiche. Nonetheless, I additionally wanted to realize that retro really feel whereas sustaining accessibility, efficiency, responsiveness, and semantics.
dialog
and ::backdrop
A quick overview of Let’s run by means of a fast refresher.
Observe: Whereas I largely confer with “dialogue containers” all through, the HTML ingredient is spelt dialog
.
dialog
is an HTML ingredient designed for implementing modal and non-modal dialogue containers in merchandise and web site interfaces. It comes with built-in performance, together with closing a field utilizing the keyboard Esc
key, focus trapping to maintain it contained in the field, present and conceal strategies, and a ::backdrop
pseudo-element for styling a field’s overlay.
The HTML markup is simply what you may anticipate:
The sort of dialogue field is hidden by default, however including the open
attribute makes it seen when the web page hundreds:
I can’t think about too many functions for non-modals that are open by default, so ordinarily I want a button which opens a dialogue field:
Plus slightly little bit of JavaScript, which opens the modal:
const dialog = doc.querySelector("dialog");
const showButton = doc.querySelector("dialog + button");
showButton.addEventListener("click on", () => {
dialog.showModal();
});
Closing a dialogue field additionally requires JavaScript:
const closeButton = doc.querySelector("dialog button");
closeButton.addEventListener("click on", () => {
dialog.shut();
});
Except the field comprises a type utilizing methodology="dialog"
, which permits it to shut robotically on submit with out JavaScript:
The dialog
ingredient was developed to be accessible out of the field. It traps focus, helps the Esc
key, and behaves like a correct modal. However to assist display screen readers announce dialogue containers correctly, you’ll need to add an aria-labelledby
attribute. This tells assistive expertise the place to search out the dialogue field’s title so it may be learn aloud when the modal opens.
Most tutorials I’ve seen embrace little or no styling for dialog
and ::backdrop
, which could clarify why so many dialogue containers have little greater than border radii and a box-shadow
utilized.

I consider that each ingredient in a design — irrespective of how small or sometimes seen — is a chance to current a model and inform a narrative about its services or products. I do know there are moments throughout somebody’s journey by means of a design the place paying particular consideration to design could make their expertise extra memorable.
Dialogue containers are simply a type of moments, and Mike Price’s design affords loads of alternatives to mirror his model or join on to somebody’s place in Mike’s story. That is likely to be by styling a publication sign-up dialogue to match the scrolls in his information part.

Or making the shape modal on his error pages appear like a comic-book speech balloon.

dialog
in motion
Mike’s drop-down navigation menu seems to be like an historical stone pill.

I wished to increase this look to his dialogue containers with a three-dimensional pill and a jungle leaf-filled backdrop.

This dialog
comprises a publication sign-up type with an e mail enter and a submit button:
I began by making use of dimensions to the dialog
and including the SVG stone pill background picture:
dialog {
width: 420px;
top: 480px;
background-color: clear;
background-image: url("dialog.svg");
background-repeat: no-repeat;
background-size: include;
}
Then, I added the leafy inexperienced background picture to the dialogue field’s generated backdrop utilizing the ::backdrop
pseudo ingredient selector:
dialog::backdrop {
background-image: url("backdrop.svg");
background-size: cowl;
}

I wanted to make it clear to anybody filling in Mike’s type that their e mail handle is in a legitimate format. So I mixed :has
and :legitimate
CSS pseudo-class selectors to alter the colour of the submit button from gray to inexperienced:
dialog:has(enter:legitimate) button {
background-color: #7e8943;
shade: #fff;
}
I additionally wished this interplay to mirror Mike’s enjoyable character. So, I additionally modified the dialog
background picture and utilized a rubberband animation to the field when somebody inputs a legitimate e mail handle:
dialog:has(enter:legitimate) {
background-image: url("dialog-valid.svg");
animation: rubberBand 0.82s cubic-bezier(0.36, 0.07, 0.19, 0.97) each;
}
@keyframes rubberBand {
from { remodel: scale3d(1, 1, 1); }
30% { remodel: scale3d(1.25, 0.75, 1); }
40% { remodel: scale3d(0.75, 1.25, 1); }
50% { remodel: scale3d(1.15, 0.85, 1); }
65% { remodel: scale3d(0.95, 1.05, 1); }
75% { remodel: scale3d(1.05, 0.95, 1); }
to { remodel: scale3d(1, 1, 1); }
}
Tip: Daniel Eden’s Animate.css library is a superb supply of “Simply-add-water CSS animations” just like the rubberband I used for this dialogue field.
Altering how a component seems to be when it comprises a legitimate enter is a superb means so as to add interactions which might be, on the identical time, enjoyable and helpful for the person.

That mixture of :has
and :legitimate
selectors may even be prolonged to the ::backdrop
pseudo-class, to alter the backdrop’s background picture:
dialog:has(enter:legitimate)::backdrop {
background-image: url("backdrop-valid.svg");
}
Strive it for your self:
Conclusion
We regularly consider dialogue containers as purposeful components, as needed interruptions, however nothing extra. However whenever you deal with them as alternatives for expression, even the smallest components of a design may also help form a product or web site’s character.
The HTML dialog
ingredient, with its built-in behaviours and styling potential, opens up alternatives for branding and inventive storytelling. There’s no purpose a dialogue field can’t be as distinctive as the remainder of your design.
Andy Clarke
Sometimes called one of many pioneers of internet design, Andy Clarke has been instrumental in pushing the boundaries of internet design and is thought for his artistic and visually gorgeous designs. His work has impressed numerous designers to discover the complete potential of product and web site design.
Andy’s written a number of industry-leading books, together with ‘Transcending CSS,’ ‘Hardboiled Internet Design,’ and ‘Artwork Path for the Internet.’ He’s additionally labored with companies of all sizes and industries to realize their targets by means of design.
Go to Andy’s studio, Stuff & Nonsense, and take a look at his Contract Killer, the favored internet design contract template trusted by 1000’s of internet designers and builders.