HTML – show / hide text

Hello friends!

Sometimes it becomes necessary to insert a code that allows you to show or hide a layer with a picture or text by clicking on the button. And although there are many options for such a solution on the Web, most of them use Java or jquery in their mechanism.

But the problem can also be solved using regular HTML tools 🙂

  1. <style>
    
  2. .del { display: none; }
    
  3. .del:not(:checked) + label + * { display: none; }
    
  4.  
  5. /* here we edit the button view */
    
  6. .del:not(:checked) + label,
    
  7. .del:checked + label {
    
  8. display: inline-block;
    
  9. padding: 2px 10px;
    
  10. border-radius: 2px;
    
  11. color: #fff;
    
  12. background: #4e6473;
    
  13. cursor: pointer;
    
  14. }
    
  15. .del:checked + label {
    
  16. background: #e36443;
    
  17. }
    
  18. </style>
    
  19.  
  20. <input type="checkbox" id="raz" class="del"/>
    
  21. <label for="raz" class="del">Show hidden text</label><div>
    
  22. <strong>Hidden text</strong> </div>

And, in fact, the code itself example: