Tutorials Logic, IN info@tutorialslogic.com
Navigation
Home About Us Contact Us Blogs FAQs
Tutorials
All Tutorials
Services
Academic Projects Resume Writing Website Development
Practice
Quiz Challenge Interview Questions Certification Practice
Tools
Online Compiler JSON Formatter Regex Tester CSS Unit Converter Color Picker
Compiler Tools

HTML Comments Add Comments in HTML: Tutorial, Examples, FAQs & Interview Tips

HTML Comments

HTML comments are notes written inside the source code. Browsers ignore them, so they do not appear on the web page. Developers use comments to explain sections, temporarily disable markup, leave reminders, or make a long document easier to scan.

A comment starts with <!-- and ends with -->. Everything between those two markers is treated as a comment by the browser.

Basic Comment Syntax
<!-- This text is a comment. The browser will ignore it. -->

<h1>Welcome to My Page</h1>
<p>This paragraph is visible in the browser.</p>

Single-Line and Multi-Line Comments

A comment can stay on one line or span multiple lines. Single-line comments are useful for short notes. Multi-line comments are useful when explaining a larger section or temporarily hiding a block of HTML during testing.

Single-Line and Multi-Line Comments
<!-- Single-line comment -->
<p>This paragraph is active.</p>

<!--
    Multi-line comment:
    The following tl-card is used on the home page.
    Keep the heading short on mobile screens.
-->
<article>
    <h2>HTML Tutorial</h2>
    <p>Learn the building blocks of web pages.</p>
</article>

Temporarily Disable HTML

Comments are often used while debugging. You can wrap an element in a comment to stop it from rendering without deleting the code. This is helpful when testing layouts, ads, scripts, or optional content.

Comment Out HTML
<h2>Product Details</h2>
<p>This content is visible.</p>

<!--
<div class="promo-banner">
    <p>Limited-time offer!</p>
</div>
-->

Comment Rules and Best Practices

Comments should make code clearer, not noisier. Write comments when the reason behind the markup is not obvious. Avoid repeating what the tag already says.

  • Do not place passwords, API keys, private URLs, or personal data inside HTML comments.
  • Keep comments short and useful so future developers can understand the page quickly.
  • Do not nest comments inside comments, because HTML does not support nested comments safely.
  • Avoid using double hyphens inside comment text, because they can confuse parsers.
Good and Bad Comments
<!-- Good: explains why this section exists -->
<!-- Featured articles are shown above the fold for editorial campaigns. -->
<section>
    <h2>Featured Articles</h2>
</section>

<!-- Bad: repeats the obvious -->
<!-- This is a paragraph -->
<p>Read our latest guide.</p>

HTML Quotations

HTML has semantic elements for quotations and source references. These elements do more than style text: they describe the meaning of the content. Use them when you quote a person, article, book, website, report, or any other source.

The main quotation-related elements are <q>, <blockquote>, <cite>, <abbr>, and <address>.

Short Inline Quotes with q

The <q> element is used for short quotations that appear inside a sentence or paragraph. Most browsers automatically add quotation marks around the quoted text.

Inline Quote with q
<p>
    The teacher said, <q>Practice a little HTML every day.</q>
</p>

Long Quotes with blockquote

The <blockquote> element is used for longer quotations that stand apart from the surrounding paragraph. When the quote comes from an online source, add a cite attribute with the source URL.

Block Quote with Source URL
<blockquote cite="https://www.w3.org/">
    <p>The power of the Web is in its universality.</p>
</blockquote>

Citing the Title of a Work

The <cite> element represents the title of a creative work, such as a book, article, research paper, poem, movie, song, website, or painting. It should not be used for a person's name by itself.

cite Element
<p>
    My favorite programming book is <cite>The Pragmatic Programmer</cite>.
</p>

<blockquote>
    <p>Programs must be written for people to read.</p>
    <footer>From <cite>Structure and Interpretation of Computer Programs</cite></footer>
</blockquote>

Abbreviations with abbr

The <abbr> element marks an abbreviation or acronym. Add a title attribute to show the full form. This helps readers, search engines, and assistive technologies understand shortened terms.

Abbreviation with Full Form
<p>
    <abbr title="HyperText Markup Language">HTML</abbr> is used to structure web pages.
</p>

<p>
    <abbr title="World Wide Web Consortium">W3C</abbr> publishes web standards.
</p>

Contact Information with address

The <address> element represents contact information for the nearest article or page. It can contain an author's email, website, physical address, social profile, or support contact. It should not be used for every postal address on a page unless that address is contact information.

address Element
<article>
    <h2>HTML Comments and Quotations</h2>
    <p>Written for beginners learning semantic HTML.</p>

    <address>
        Written by <a href="mailto:editor@example.com">Tutorial Editor</a><br>
        Visit: <a href="https://example.com">example.com</a>
    </address>
</article>

Quotation Elements Reference

Use the correct element based on the meaning of the text. The browser may style these elements differently, but their main purpose is semantic structure.

Element Purpose Example Use
<q> Short inline quotation A quote inside a paragraph
<blockquote> Long block-level quotation A quoted passage from an article
cite attribute Machine-readable source URL <blockquote cite="...">
<cite> Title of a creative work Book, article, movie, report, website title
<abbr> Abbreviation or acronym HTML, CSS, API, W3C
<address> Contact information Author email or organization contact

Complete Practical Example

The following example combines comments, quotations, citations, abbreviations, and contact information in one semantic article section.

Complete Comments and Quotations Example
<!-- Article introduction for the HTML learning series -->
<article>
    <h1>Why Semantic HTML Matters</h1>

    <p>
        <abbr title="HyperText Markup Language">HTML</abbr> gives meaning
        to the structure of a web page.
    </p>

    <p>
        As many developers say, <q>Good markup is the foundation of good websites.</q>
    </p>

    <blockquote cite="https://www.w3.org/">
        <p>The Web is designed to work for all people, whatever their hardware, software, language, location, or ability.</p>
        <footer>Source: <cite>World Wide Web Consortium</cite></footer>
    </blockquote>

    <address>
        Contact the editor at
        <a href="mailto:editor@example.com">editor@example.com</a>.
    </address>
</article>

Common Mistakes

  • Do not use comments to hide sensitive information. Comments are visible in page source.
  • Do not use <q> for long paragraphs. Use <blockquote> instead.
  • Do not use <cite> for a quote itself. Use it for the title of the source work.
  • Do not use <address> for random addresses that are not contact information.

Frequently Asked Questions

HTML comments are not displayed on the page, but users can still see them by viewing the page source or inspecting the HTML. Never put sensitive information in comments.

<q> is for short inline quotes inside a sentence. <blockquote> is for longer quotes that should stand as a separate block.

The cite attribute stores the source URL for a quote. It is machine-readable metadata and is usually not shown visually by browsers.

No. The <cite> element marks the title of a work, while the cite attribute provides a source URL for <q> or <blockquote>.

Key Takeaways
  • HTML comments use <!-- and --> and are ignored by browsers.
  • Comments are useful for notes, explanations, debugging, and temporarily disabling markup.
  • Comments are visible in page source, so never store passwords, API keys, or private data in them.
  • Use <q> for short inline quotations and <blockquote> for longer block-level quotations.
  • Use the cite attribute to provide a source URL for quoted material.
  • Use <cite> for the title of a work, <abbr> for abbreviations, and <address> for contact information.

Ready to Level Up Your Skills?

Explore 500+ free tutorials across 20+ languages and frameworks.