Add comments to HTML

Author: Tamara Smith
Date Of Creation: 19 January 2021
Update Date: 1 July 2024
Anonim
HTML - Comments
Video: HTML - Comments

Content

Inserting comments into your code allows you to post descriptions and explain code for yourself and other programmers who will be working on the page. Comment tags can also be used to quickly turn off certain parts of your code during testing, or when working on new features that have not yet been completed. By learning how to post comment tags you can program more efficiently, which is useful for both yourself and your colleagues.

To step

  1. Enter a comment in one line. "Comments" are determined by the tags used !-- and -->. You can enter short comment tags to help you remember what certain code does.

    html> head> title> Comment test / title> / head> body>! - This code creates a paragraph -> p> This is the website / p> / body> / html>

    • Make sure there are no spaces between the comment tags. For instance  !-- will not activate the comment function. Within the tags you can add as many spaces as you want.
  2. Comment in multiple lines. Your comment can be spread over several lines, which is useful for explaining complex code, or for blocking large chunks of code.

    html> head> title> Comment test / title> / head> body>! - Your comment can be as long as needed. Everything within the comment tags will not be executed and thus has no effect on the page. -> p> This is the website / p> / body> / html>

  3. Use the comment function to quickly disable code. If you want to find a bug in the code, or if you don't want code to run on the page, you can use the comment function to quickly block code. That way, removing the comment tags makes it easy to restore code.

    html> head> title> Comment test / title> / head> body> p> View these images / p> img src = "/ images / image1.webp">! - This image will now be hidden first img src = "/ images / image2.webp "> -> / body> / html>

  4. Use the comment function to hide scripts on unsupported browsers. If you're programming in JavaScript or VBScript, you can use the comment function to hide the script in browsers that don't support it. Add the comment at the beginning of the script and close it with //--> to make sure the script works on browsers that support the well support.

    html> head> title> VBScript / title> / head> body> script language = "vbscript" type = "text / vbscript">! - document.write ("Hello World!") // -> / script> / body> / html>

    • It // in the end tag prevents the script from being executed by the comment function, if scripts are supported by the browser.

Tips

  • Use comments as much as possible, as they will make it much easier to understand your code at a later point in time and to remember how everything worked again.