<!DOCTYPE html> <!-- fieldset with no elements and invalid element is added dynamically --> <html> <head> <style> fieldset:invalid { display:none } </style> <script> function onLoadHandler() { document.getElementById("fieldset").appendChild(document.getElementById('i')); document.documentElement.className=''; } </script> </head> <body onload='onLoadHandler();'> <input id='i' required> <fieldset id="fieldset"> </fieldset> </body> </html>