HOWTO · Batch

How to Add Comments in Batch Script

This tutorial provides a comprehensive guide on how to add comments in Batch scripts. Learn the available methods, including the REM command and double colons, and why GOTO — which redirects execution — is not a comment method. Discover best practices for writing effective comments that clarify your code for yourself and others.

On this page

When adding comments to a Windows Batch (.bat or .cmd) file, use REM for the clearest, most reliable choice. A line beginning with :: is also commonly used as a comment, but it is parsed as a label and has placement caveats. Use either form to explain intent; neither form changes what the script is meant to do.

Choose a Batch comment form: REM or ::

REM is a command whose purpose is to mark a remark. It is the standard option and is the better default when a comment appears inside a parenthesized command group. The :: form is a label-like idiom: CMD treats it as a label rather than as a dedicated comment command. It is concise for standalone notes, but labels can interact with block parsing and control flow. For predictable scripts, prefer REM when the surrounding syntax is complex.

Both forms are specific to Windows CMD Batch. They are not portable comment syntax for PowerShell, Bash, or other shells. Put comments on their own lines when possible, and keep the wording focused on why a command is needed or what assumption it relies on.

Add single-line comments with REM or ::

The following Windows CMD sample is a small working pattern to save as comments.bat. It uses one REM line and one :: line before commands, so you can compare the forms in context. The sample ran successfully and printed the two status lines shown below.

@echo off
REM Describe the next action for the person maintaining this file.
echo Preparing the report
:: This label-like line is commonly used as a short note.
echo Report ready
Preparing the report
Report ready

When CMD reaches a REM command, it ignores the remark text as an instruction. A :: line is treated as a label and is commonly used for the same visual purpose. The commands after each note still run. The text in either comment should avoid suggesting that the script performed work it does not actually do.

Handle comments inside command groups and after commands

A comment may appear between commands. For example, a REM line can sit between an IF line and the commands that follow it. Within a parenthesized group, use REM on a separate line and keep comment text free of characters that can affect CMD’s parsing of the whole group, especially unmatched parentheses. CMD may expand %name% while parsing a parenthesized command block, including text on a REM line. The remark is discarded rather than displayed, but expansion can still change how the block is parsed; keep such notes plain and avoid percent expressions in them. Keep block comments plain and simple.

For a short trailing remark after a command, separate it with & and use REM, as in echo Preparing the report & REM this command prints the status. The ampersand starts another command on the same line; it does not make every comment form safe in every context. Avoid appending :: to a command, and avoid putting comments after an IF command whose ELSE clause must remain associated with it. If a line combines conditional syntax, a command separator, or a parenthesized group, move the note to its own line instead. This makes the command structure easier to read and reduces parsing surprises.

Write multi-line notes safely

Batch has no native block-comment delimiter. The straightforward way to write a note across several lines is to prefix each line with REM (or, for simple standalone notes, ::). Repeating REM is preferable around command groups because it is a real command and its purpose is explicit.

GOTO redirects execution to a label, so it changes the script’s control flow and is not comment syntax. Do not use it to mark a block as a comment; repeat REM on each line for a multi-line note.

Choose REM for the general case, reserve :: for standalone label-like notes where the surrounding structure is simple, and keep comments on separate lines around conditional or grouped commands. These examples target Windows CMD Batch files and should not be copied as comment syntax into another shell.