javascripthtmlcsshidelibraries

How do I hide a section of HTML without removing it?


I want to hide a section of HTML, and stop it being viewable from the webpage itself without removing it. Is this possible in HTML or CSS, or can anyone recommend a Javascript library capable of doing this? The part that needs hiding looks similar to this:

<p>text1<strong>text2</strong></p>

I don't want it to display on the website but I do want it viewable when looking at the code directly.

Any ideas?


Solution

  • Add a "hidden" class to select the target HTML and use display: none in CSS:

    HTML:

    <p class="hidden">text1<strong>text2</strong></p>
    

    CSS:

    .hidden {
      display: none;
    }
    

    ...or you could inline it directly:

    <p style="display:none">text1<strong>text2</strong></p>