css – Is it possible to add a blur to the HTML5 dialog backdrop?-ThrowExceptions

Exception or error:

I’m trying to add a blur effect to the backdrop of a dialog (I realise dialog currently only has limited support – I’m using Chrome v66).

I’ve tried adding a blur filter to the ::backdrop css (no luck), and the backdrop-filter isn’t supported yet.

Anyone know what I should be doing instead?

window.onload = function() {
  document.getElementById('mydialog').showModal();
}
dialog::backdrop {
  background: rgba(255, 0, 0, .25);
}

/* attempt #1 - using a blur filter */
dialog::backdrop {
  -webkit-filter: blur(2px);
  -moz-filter: blur(2px);
  -o-filter: blur(2px);
  -ms-filter: blur(2px);
  filter: blur(2px);
}

/* attempt #2 - using backdrop-filter */
dialog::backdrop {
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

/* attempt #3 - using an svg */
dialog::backdrop {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100%' height='100%'><defs><filter id='blur'><feGaussianBlur stdDeviation='5' /></filter></defs><rect filter='url(%23blur)' fill='rgba(255,255,255,0.5)' x='0' y='0' width='100%' height='100%'/></svg>");
}
Here is some other text that I want blurred.
<dialog id="mydialog">This is the dialog window</dialog>
How to solve:

So not an ideal solution (I’d prefer to use css only), but this is an example workaround using javascript to apply a .blur class to the body.

window.onload = function(){
  document.getElementById('mydialog').showModal();
  document.getElementsByTagName('body')[0].classList.add("blur")
}
dialog::backdrop {
  background: rgba(255,0,0,.25);
}
.blur {
  -webkit-filter: blur(2px);
  -moz-filter: blur(2px);
  -o-filter: blur(2px);
  -ms-filter: blur(2px);
  filter: blur(2px);
}
Here is some other text that I want blurred.
<dialog id="mydialog">This is the dialog window</dialog>

Leave a Reply

Your email address will not be published. Required fields are marked *