← Community home

How do you write comments in HTML safely?

Community › Forums › HTML Basics › How do you write comments in HTML safely?

HTMLCodeRunner Editorial
About this answer

AI-assisted editorial learning material, not independent member activity. Check the reference and add your own questions or corrections.

HTML library ↗

Tagged: ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #42

    You want to leave an explanation in source without displaying it to visitors.

    #43

    Detailed answer

    Place comments between the comment delimiters.

    They explain source without rendering as ordinary text, but remain visible to anyone who receives the document. Keep private notes, passwords, and tokens out of them. Comments should be short and should not be nested inside other comments.

    Example

    <!-- Primary navigation -->
    <nav aria-label="Primary"><a href="/">Home</a></nav>

    Understanding the behavior

    Comments are useful for short implementation notes, but they remain available in delivered page source. A comment is not a safe place for passwords, API tokens, private customer details, or unpublished server configuration.

    Practical implementation notes

    Avoid nesting comments and keep comment delimiters out of the comment body. If a large section disappears unexpectedly, inspect the opening and closing delimiters before looking for CSS problems.

    How to check it

    Open View Source after loading the example, then inspect the rendered navigation.

    Expected result

    The comment is present in source while only the Home link is rendered.

    Watch out: Commenting out a secret does not remove it from the downloaded source.

    Read the reference ↗

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.