Skip to content
FLAVIO COPES
flaviocopes.com
2026

How to hide a DOM element using plain JavaScript

By Flavio Copes

Learn how to hide a DOM element with plain JavaScript by setting its style.display property to none, then show it again with block or inline.

~~~

How do you hide a DOM element using plain JavaScript?

Every element exposes a style property which you can use to alter the CSS styling properties.

You can set the display property to ‘none’ (like you would do in CSS, display: none;):

element.style.display = 'none'

To display it again, set it back to block or inline:

element.style.display = 'block'
~~~

Related posts about js: