Hide HTML elements

Hide HTML Elements

There are times when you may want to hide certain HTML elements from your website visitors. This can be for various reasons, such as hiding a section that is not yet ready to be displayed, or hiding a menu on certain pages where it is not needed.

Using CSS

The most common way to hide HTML elements is by using CSS. You can do this by setting the display property to none. This will remove the element from the page completely.

.hide {
  display: none;

You can then add the hide class to any element that you want to hide.

Using JavaScript

If you want to dynamically hide an element based on user actions, you can use JavaScript. You can do this by selecting the element and setting the style.display property to "none".

document.getElementById("myElement").style.display = "none";

This will hide the element with the ID of myElement.

Using ARIA Attributes

If you want to hide an element from screen readers, but still have it visible on the page, you can use ARIA attributes. You can do this by setting the aria-hidden attribute to true.

<div aria-hidden="true">
  This content is hidden from screen readers.

This will hide the content from screen readers, but it will be visible on the page.


These are just a few ways to hide HTML elements on your website. Depending on your needs, you may choose to use one or more of these methods. Always make sure to test your changes across different browsers and devices to ensure that everything works as expected.

Subscribe to The Poor Coder | Algorithm Solutions

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]