Skip to content
the poor coder

Hide HTML elements

Poor Man
Published
Reading time
1 min read
On this page

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.

CSS

.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".

JavaScript

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.

HTML

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

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

Conclusion#

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.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC