HTMLs Tutorial

HTML Tutorial HTML Tags HTML Basic Tags HTML Attributes HTML Elements HTML Formatting HTML Text Format HTML body tag HTML samp tag HTML script Tag HTML section tag HTML select tag HTML source tag HTML span tag HTML strike tag HTML strong tag HTML style tag HTML sub tag HTML summary tag HTML sup Tag HTML svg tag HTML table tag HTML u tag HTML Headings HTML Paragraphs HTML wbr tag HTML Anchor HTML Image HTML Lists HTML Ordered List HTML Unordered List HTML Form HTML Form input HTML with CSS HTML Layouts HTML References HTML Frames HTML Links Fieldset Tag in HTML Basic HTML Tags Br Tag in HTML Free HTML Templates How to Create a Table in HTML HTML Calendar HTML Card HTML Cellspacing HTML Center Image HTML Checkbox Read-only HTML Cleaner HTML Code for a Tab HTML Comment HTML Compiler HTML Nested Forms HTML Overlay Text on the Image HTML Select Option Default HTML Snake Game HTML Subheader HTML Tab Character dd Tag in HTML How Many HTML Tags are There HTML Align Tag HTML Responsive HTML Tab Code HTML Table Alternate Row Color HTML Table Fix Column Width Contact HTML DL Tag in HTML How to Insert Image in HTML HTML Background Color HTML Dark Mode How to Convert HTML to PNG HTML Data Toggle HTML Email Template HTML Font Color HTML Font Family ID and Class in HTML HTML Tab Space HTML Tab Tag HTML Itemprop HTML Itemscope HTML Form Design HTML Input Only Numbers HTML Textarea HTML to JPG HTML to Markdown Python li Tag in HTML MDN HTML What is the Correct HTML for Making a Hyperlink? What is the Root Element of an HTML Document How to Make a Box in HTML How to Save HTML Files in Notepad How to Align Text in HTML How to Change Font Color in HTML? How to Change Font Size in HTML How to Change Image Size in HTML How to Create a HTML Page How to Create a Link in HTML File? How to Create an HTML File? HR Tag in HTML HTML Base Tag HTML Default Attribute HTML Hyperlink HTML Indent HTML Injection Payloads HTML Input Numbers Only HTML Roadmap HTML Row Height HTML Schedule HTML Space HTML Tab HTML vs HTTP HTML5 API HTML5 Video HTML Collection to Array Text Area in HTML

HTML5 Advance

HTML5 Tutorial HTML5 Tags HTML Button Tag HTML canvas Tag HTML caption Tag HTML City tag HTML Tag HTML5 SVG HTML Event Attribute HTML5 Audio HTML5 Youtube HTML5 Button Tag HTML5 Tags

Misc

How to add JavaScript to HTML How to change font in HTML How to change text color in HTML HTML Date HTML Hide Element HTML Nested Table HTML Reset Button What does HTML stand for? HTML Background Image HTML Tag Div Tag in HTML How to insert Image in HTML How to create a link with no underline in HTML How to insert spacestabs in text using HTMLCSS HTML tag HTML Code HTML Tag HTML Canvas Design a tribute page using HTML and CSS What is a Container tag Font tag in HTML Difference between HTML and DHTML Empty Tag in HTML HTML Button Link Html Line Break Img src HTML Nested List in HTML Placeholder in HTML TD in HTML HTML Space Code HTML Target Attribute HTML Tag Markup Meaning in HTML Border-Collapse in HTML HTML Onclick Online HTML Compiler Convert HTML to PDF HTML Formatter HTML5 - Web Storage HTTP – Responses Container Tag in HTML DL Tag in HTML Horizontal Rule HTML HTML Tab Text Html Table Cell Background Color HTML Table Cell Color HTML Col Width How Many HTML Tags are There Convert String to Unicode Characters in Python HTML Runner HTML Style Attribute HTML Superscript Attribute HTML tabindex Marquee Tag in HTML HTML Dynamic Form HTML side Tag HTML Pattern Attribute HTML q Tag HTML Readonly Base 64 Encoding in HTML Documents Enhancing Data Portability and Security Evo Cam Web Cam HTML Free code camp HTML CSS How to Add a JS File in HTML? How to Add Picture in HTML How to Add the Logo in HTML? How to Add Video in HTML HTML Class Attribute HTML Entities HTML Form Elements HTML Form Templates HTML Marquee Tag HTML Radio Buttons HTML Text box HTML to JSX HTML Tooltip Basic HTML Codes How to Align Image Center in HTML HTML Header Tag HTML Image Tag HTML Next Line

HTML Comment

Introduction

Comments provide extra pertinent information in an HTML document. Browsers on webpages do not render HTML comments; instead, they are only visible when a web page's source code is examined. Comments are vital to developers because they enable them to understand the true purpose of a piece of code.

Assume that a group of developers is collaborating on the same project. In this case, the other developers must comprehend the job that one developer has completed. That is where comments play a crucial role in fostering conversation.

Using the HTML comment tag An HTML comment often follows this syntax:

<!-- I am a comment! -->

In HTML, comments are terminated with --> and begin with <!--

Remind yourself to start the tag with an exclamation point! Yet, it's not necessary to include it in the conclusion.

You may comment out any text or other HTML element that surrounds it.

Value of HTML Comment

  • Enhances the code's readable quality, particularly when different developers view the same HTML source.
  • Enables rapid and effective comprehension of complex code.
  • Facilitates simpler maintainability and source code debugging.

How and When to Use HTML Comment

Browsers do not show HTML comments. That implies that when the page is produced in a web browser, any comments you make to your HTML source code will be hidden.

Remember that almost any website put online may have its source code seen by anybody by going to View -> Developer -> View Source; this also applies to comments!

Hence, if you make the HTML content public and someone else decides to look at the source code, their comments will be available to others.

While writing source code, it's a good idea to include comments, as they may be useful. By using comments, you may better document and communicate with yourself (and others) about your code and thinking process. Returning to a project after months away from it also serves as a reminder of your previous thoughts and actions. You may also interact with other developers working on the project by using comments. They can easily understand your reasoning for adding certain lines of code from your comments.

Adding HTML Comments Using a Keyboard Shortcut

You'll likely use the commenting shortcuts often. The shortcut is Command (on a Mac) or Control (on Windows and Linux).

Hold down the key combination seen above while in the code editor to add a single-line commentary. Next, a comment will be added to the whole line you are on. Just be aware that this only works for single-line comments since everything else will be commented on on that line. Inline comments must be added by hand.

Press and hold the two keys shown above to create a multi-line comment. First, select and highlight all the text or tags you want to comment on. A remark will now appear on each line you choose.

Example

<script type="text/javascript">

<!--

function displayMsg() {

  alert("Hello")

}

//-->

</script>

How are HTML Comments Used?

We mostly utilize comments to improve readability in our code. Only the code displays them; they are entirely concealed from the site.

When we provide comments on your code, we can better communicate what it is doing. In the future, you may use them as an anchor if you decide to modify your code.

Additionally useful to other developers in a collaborative context are code comments.

You may enter notes describing the code or use HTML comments to designate portions of a document. These improvements improve the code's readability and comprehension. Instead of removing temporary code blocks, you may use the comment tag to exclude them.

The <!--... --> element is used to define HTML comments. Browsers do not see the content of this element because they disregard it.

The comment element can only be used in a limited number of browsers to comment on a section of HTML code. All page areas accept HTML comments except the <title> element. Additionally, they are inoperable within the <style> element since CSS has a different commenting syntax.

What Constitutes a Valid Comment?

One comment cannot be placed inside another. If it is not part of the closing (-->) tag, the double-dash sequence ("--") may not appear within a comment. Furthermore, it is crucial to confirm that the start-of-comment string is free of spaces.

Several-line Remarks

HTML allows comments to be one line or many lines. The starting tag \!-- and ending tag --> may be used to create multi-line comments.

Commenting on Style Guides

When using CSS in HTML code, it is advised to include the style sheet code within the relevant HTML comments so that older browsers can function properly.

Making Script Code Comments

When employing JavaScript or VBScript in HTML code, it is advised to include script code within the required HTML comments to ensure that older browsers continue to function properly.

Example

<!DOCTYPE html>

<head>

    <title>Single-Line Comment</title>

</head>

<body>

    <!-- This is a single-line HTML comment. -->

   <p> This is an example of a single-line comment.</p>

</body>

</html>

What Constitutes a Valid Comment?

Here are some basic guidelines for creating an HTML comment that is valid:

  • Comments in HTML do not nest. That implies that comments cannot be nested inside of comments.
  • Additionally, unless it is a component of the closing (->) tag, we are not allowed to use the double-dash sequence ("-“) in comments. In other words, comments begin with "." Nowhere in the remark do they use the letter "-."
  • The start-of-comment string has to be checked to ensure no spaces are in it.