Based in Omaha, NE, USA
The Desert Dome and flower gardens at the Henry Doorly Zoo in Omaha, Nebraska

How Do You Add Comments in HTML When Designing a Website?

Work from home

Make money from home as a Websnoogie reseller

Zero upfront cost and no hidden fees. Sell websites and hosting under your own business name or under ours, and we build, host and support every site. You find the customers and we do the rest. We pay fast, usually within 72 hours. Call us any day from 7 am to 10 pm, or see how it works.

Become a reselleror call 402-813-4034

A smiling African American woman with natural curly hair, in a tan sweater, sits at a computer in a bright home office with a coffee mug and a green plant on the desk and looks up warmly
Laptop on a bright desk showing lines of code shapes with highlighted note lines and sticky notes beside it

An HTML comment is a note that the browser skips. Start it with <!-- and end it with -->. Visitors do not see it on the page.

Why use comments

When you build a custom website, you may want notes that visitors do not see. An HTML comment does that. The browser skips it, but anyone who views your HTML code can read it.

Use comments to mark where you placed a javascript or PHP application. Use them to describe one area of the page, or to add a date stamp to a section.

Comments keep your code easy to read when you come back to it months later.

Flat illustration of a golden sticky note attached to a block of code lines to show a hidden comment

The comment syntax

To make a comment, type the following code.

HTML
<!-- Your comment or information -->

Start with the opening marker and end with the closing marker. Everything between the two stays hidden on the page.

Comments that run over several lines

A comment can cover more than one line. Use this to describe a larger section.

HTML
<!--
  Header area
  Updated by the web team
  Holds the logo and menu
-->
<header>...</header>

The browser ignores every line between the markers. This keeps long notes tidy.

Switch off a block of code

You can also use comments to switch off code while you test. Wrap the block in the markers.

HTML
<!--
<div class="banner">
  Spring sale details
</div>
-->

The browser ignores the block. Remove the markers to turn it back on. Do not put a comment inside another comment, because the first closing marker ends both.

Comments in other languages

HTML comments only work in HTML. CSS uses a different marker. In a style sheet, write /* your note */. PHP uses // for one line, and /* */ for several.

A common mistake is to use the HTML marker inside a style sheet or script. It will not work there. Use the marker that matches the language of the file.

Good habits for comments

Mark the start and end of each major section. This helps you find the right place fast. For example, note where the header ends and the main content begins.

In WordPress, you can add comments to your theme files the same way. Remember that visitors can read them in the page source, so keep them professional.

If your page looks broken, a missing closing marker is the usual cause. The browser then hides everything after the comment starts. Check that every opening marker has a closing one.

A short example from a real page

Say your page has a contact form from a PHP script. Put a note above it that says where the form starts and which file handles it. A month later, you will know right away what that block does.

The same habit helps when a teammate opens your files. They can follow your work without asking you questions.

Keep private details out of comments

Do not put passwords or private notes in a comment. Anyone can open the page source and read it. Treat every comment as public.

Also keep your comments short and clear. A note like "menu starts here" is enough. Old comments that no longer match the code can confuse the next person.

Need a custom website? We build a new website with up to 10 pages for $300, in 3 to 5 days. Our Omaha web design team answers at 402-813-4034 any day from 7 am to 10 pm.

Rod Atwood, the bearded founder of Websnoogie, beside Tami Atwood, who wears glasses, both smiling

AboutRod and Tami Atwood

Rod and Tami Atwood and other Websnoogie contributors write the Websnoogie blog. Rod has built websites since 2004 and founded Websnoogie, LLC in Omaha in 2012. Tami is co-owner, content editor and billing expert. Call us at 402-813-4034 or write to staff@websnoogie.com.

  • Facebook social media logo
  • X social media logo
  • Instagram social media logo
  • Pinterest social media logo
  • LinkedIn social media logo
  • YouTube social media logo
  • TikTok social media logo
  • Threads social media logo
  • Google Business Profile social media logo

Get started with Websnoogie

A smiling couple at a sunlit office desk reviewing a colorful website on a large monitor

A family company in Omaha

Rod, Tami, and their team have built websites, content, and provided SEO services (internet marketing) for over 20 years. You call us, you talk to us. Most new websites are ready in 3 to 5 days, and our hosting runs at 99.999% uptime.

  • Best of Omaha B2B winner, 2021 to 2025
  • BBB accredited with an A+ rating
  • Small businesses, nonprofits and professionals

Sign up now

Due today$449

  • Visa
  • Mastercard
  • American Express
  • Discover
  • Apple Pay
  • Google Pay
  • Cash App Pay
  • PayPal

Secure checkout with Square or PayPal

More info on our products

Contact us now!

Prefer to talk? Call 402-813-4034 or email staff@websnoogie.com. We are open every day, 7 am to 10 pm.

Graphical site map