Did you know there’s a way to hide an HTML code or text snippet on your site?
Every once in a while, it may be necessary to hide text or content on a website. For example, if you need to remove a segment of text, because a situation has changed, yet you want to keep it just in case you need to restore it later. Instead of deleting the content entirely, it’s possible to hide it behind a unique code.
When hidden, the text remains part of the HTML that you’ve written on the backend of your site, but it’s not visible to the average user. This is also an excellent tool to use when following an HTML tutorial or learning the language. You can play around with the visibility of text and content rather easily.
How Do You Hide an HTML Code?
The process for hiding HTML is pretty easy, and it involves doing something called “commenting out” the content. When you create documents in HTML, you can leave comments to help other developers and designers understand what each snippet is for.
In your coding tool, whether that’s something like notepad, a developer studio, or just a web editor, you’ll want to do the following:
1) Find the paragraph or block of text you wish to hide. Make sure your active cursor is at the front of that block and click to edit.
2) Type this before the first character:
<!---
This tells browsers and applications to hide anything after.
3) Find the last character in the block of text you want to hide, move the cursor there to edit.
4) Type this after the last character:
--->
This tells the browser to stop hiding the content.
5) Save your document, and either upload it to your website’s server or test it in a browser window.
What Is “Comment Code” Used for?
Every developer or coder has a different approach. When you write code you often add a bit of your personality to the project, because there are many ways to achieve a particular function or task. When someone else comes in to clean up or work on your code, they might not understand what you were trying to do or why you did something a particular way. That is precisely what HTML comments are for, and they also exist across every programming language.
So, even though we did this with HTML, you can do the same thing with other languages too. The code to do so is different from language to language, so keep that in mind.
You can comment out certain blocks of text or content to detail what you are doing with the active code. You can also use this to hide certain content, just like we did above.
Give it a try next time you’re writing code!
Disclosure of Material Connection: Some of the links in the post above are “affiliate links.” This means if you click on the link and purchase the item, I will receive an affiliate commission. Regardless, I only recommend products or services I use personally and believe will add value to my readers.