How to Hide Elements with CSS on Your Website
When you are running a business website, it is essential to keep it fresh-looking and up to date with the latest trends and UI implementations. Even if you have a top-notch theme right now, it will need a few tweaks here and there in the future. Learning to change specific key properties of the elements and how they are displayed will help when all you have to make is simple adjustments without affecting the website functionality.
In that vein, here is a brief guide on how you can CSS hide elements on your website.
Why Hide An Element?
Say you want to remove the header navigation bar on your casino blog. To do that, you may have to edit the entire theme and make sure all relevant references are adequately taken care of. This calls for a full-on enhancement task and subsequent regression testing to ensure nothing else breaks after removing the element.
But why go through all the trouble when you can simply hide the element. You achieve the look you want without necessarily breaking down or changing a considerable part of your existing theme code. HTML hide elements properties provide a quick fix and are often used in cases such as:
- Post level element changes such as hiding the comment section for a particular blog post
- Adjusting font or headline size for selective blog posts or web pages on your free theme
- One-off case implementations where the rest of the website’s styling is not affected
- Hide elements such as animations based on user preferences
How To Hide Elements With CSS
There are multiple ways to hide your elements using display CSS options without using any WordPress plugin. But before we list down these methods, there are a few considerations such as the layout, animation, performance, and event handling that you need to take care of before deciding to hide an element.
- Hiding elements can altogether remove the relevant animation.
- Remember to take care of the accessibility options associated with the element if you will hide an element. For instance, even if you hide an image, the screen reader may read its alt text aloud. Use ARIA attributes such as aria-hidden= “true” for appropriate behavior.
- Handle any events associated with the hidden element. For instance, even if you have hidden a button, clicking on its area might induce a click event.
- Before you try to hide the element, locate the element and assign it to a class specifier to apply the CSS properties. You can use the inspect tool from the browser to find the particular CSS Id or class associated with the element. You can then make the property modifications to the corresponding CSS class to hide the element.
Here are some of the methods you can use to hide HTML code using CSS:
Change Opacity To Completely Transparent
opacity: N and filter: opacity(N)
These properties can be used to alter the transparency of the element. Setting them to 0 will make the object completely transparent. When you make an element fully transparent, it will be hidden from view on the page, but the associated events will still be used.
Color
The color property value consists of an extra field that can be used to set the alpha transparency for the element. All color properties such as the color, background-color, and border-color can be given values in terms of rgba (0,0,0,0). This value will render the element to be completely transparent on the page.
You can also set the alpha transparency using values expressed in terms of transparent property, RGBA values (red, green, blue, and alpha), HSLA values (hue, saturation, lightness, and alpha), and in the format #RRGGBBAA and #RGBA.
Using Transform Property
The transform property can be used to skew the element and change its scaling. You can move the element offscreen by setting the value of scale to zero or the position to a negative value.
.elem {Transform :scale(0) }
.elem {transform: translate (-999px,0);}
As you move the element out of the viewing area, the original layout will remain unaffected. And no events will be triggered as the element cannot be accessed from the rendered page.
Use Clip-Path
This property specifies a clipping region where the element will be visible. Setting it to zero value will hide the element.
.item {
clip-path: circle(0);
}
Using CSS Display Property
CSS display none is possibly the easiest method as it removes the element entirely. Set the display property to none, and the element will not be rendered on the page. The existing layout will adjust itself.
.item {
display:none;
}
Using Visibility Property
The visibility property is similar to the display property, except that it does not remove the element from the page. You are just making the element invisible. Hence, the original layout will remain as it is while the element will be hidden from the user. When you apply this property, the child elements of the element will still be visible, whereas using the display properly will remove them as well.
Hiding Elements On Specific Pages In WordPress
Here are the steps to hide CSS elements only on specific pages on your WordPress site.
- Find the page ID of the page. You can get this information from the URL of the page. To see the URL, go to the Page list and hover over the page, and you can see the full URL in a tooltip. Alternatively, you can also find the ID by looking at the URL bar of the page preview or the Edit page window.
- Use the page id as the CSS class where you apply the property changes to hide the element.
.page-id-number .item {
display:none;
}
You are done!
Conclusion
So, these are all the steps you need to adopt to hide elements with CSS on your website. Try the methods we discussed above, and do not forget to share your experience with us in the comments below.



