rem - Comment

Maintained on
Table of Contents

If you revisit a batch file later or hand it to someone else, leaving comments that explain the intent of each step makes it much easier to read.

The rem command is the official way to write comments in a Windows batch file.

This article explains the basics of rem, its relationship with @echo off and @rem, and how it differs from the commonly seen ::.

Copy-and-Paste Cheat Sheet

GoalSyntax
Write a one-line comment (standard)rem comment
Hide the comment line from the screen@rem comment
Add a comment at the end of a command lineecho hello & rem comment
Temporarily disable one linePut rem at the start of the line
Disable several lines at onceWrap them with goto skip_block and :skip_block (see below)
Quick shorthand (not recommended):: comment

Basics of the rem Command

The basic syntax for a comment is:

rem comment

For example:

sample.cmd
@echo off
setlocal

rem Ask the user for a favorite fruit
echo Please enter your favorite fruit.
set /p fruit=Example: apple

endlocal

When you run this batch file, the comment stays in the file as an explanation, and the only messages shown on screen are those printed by echo.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>sample.cmd
Please enter your favorite fruit.
Example: apple

Why Comments Sometimes Appear on Screen

rem does not display comments.

Comments sometimes show up on screen because command echo is on, so the line itself is printed.

sample.cmd
setlocal

rem Ask the user for a favorite fruit
echo Please enter your favorite fruit.
set /p fruit=Example: apple

endlocal
- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>sample.cmd
C:\Users\user>setlocal
C:\Users\user>rem Ask the user for a favorite fruit
C:\Users\user>echo Please enter your favorite fruit.
Please enter your favorite fruit.
C:\Users\user>set /p fruit=Example: apple
Example: apple

The Difference Between @echo off and @rem

@echo off

Putting @echo off at the top of a file stops the following command lines from being displayed. It is the most common way to start a batch file.

@rem

@rem suppresses command echo for that one line only.

sample.cmd
setlocal

@rem Ask the user for a favorite fruit
echo Please enter your favorite fruit.
set /p fruit=Example: apple

endlocal
- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>sample.cmd
C:\Users\user>setlocal
C:\Users\user>echo Please enter your favorite fruit.
Please enter your favorite fruit.
C:\Users\user>set /p fruit=Example: apple
Example: apple
Use @echo off by default

To hide unnecessary command lines for the whole batch file, put @echo off at the top. Use @rem when you only want to suppress a single line.

Writing a Comment at the End of a Line

rem is treated as a command, so to place it after another command on the same line, join them with &.

echo Starting process & rem start message
A rem line is a comment all the way to the end

Everything after rem, including &, is treated as part of the comment. Commands placed after rem on the same line are not executed.

Is It OK to Use ::?

You will often see :: comment in batch files.

However, :: is not an official comment command. It abuses label syntax, so it can behave unexpectedly inside parenthesized blocks or when combined with redirection.

Use rem when reliability matters

For maintainability and safety, rem is the safer choice for comments. It is especially recommended for reusable or shared batch files.

Commenting Out Code

Batch files have no official multi-line comment syntax like /* ... */ in C.

To temporarily disable several lines, adding rem to each line is the clearest and safest approach.

rem copy source.txt backup\source.txt
rem move source.txt archived\source.txt
rem echo Done

Commenting Out Multiple Lines at Once

When there are many lines, you can use goto to jump over the range.

sample.cmd
@echo off
echo Starting

goto skip_block
echo This is never executed
copy source.txt backup\source.txt
:skip_block

echo Finished
- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>sample.cmd
Starting
Finished
Not usable inside parenthesized blocks

A label written inside ( ) breaks the block’s parsing and cannot be a jump target. Inside if or for blocks, put rem on each line instead. Also keep label names unique within the file.

Character Encoding Pitfalls

rem itself does not cause errors. The usual problem is a mismatch between the batch file’s character encoding and the code page used by cmd.exe.

Batch files that contain Japanese or other non-ASCII comments can show garbled text depending on the environment.

UTF-8 is not always safe

Batch files with non-ASCII text can behave differently depending on the environment, whether saved as UTF-8 or Shift_JIS. Save in the encoding your existing setup uses, and test on the real machine, including chcp 65001 if needed.

Summary

  • The official way to write a comment is rem comment
  • Comments appear on screen because of command echo, not because rem prints them
  • Use @echo off for the whole file, or @rem for a single line
  • :: is a shortcut; rem is safer when robustness matters
  • With non-ASCII comments, check the combination of file encoding and code page

Practice Questions

Practice Problem

Which of the following is treated as an official comment in a batch file?

Choose one answer.

  1. rem This line is a comment
  2. echo This line is a comment
  3. pause This line is a comment

Practice Problem

What do you often write first to suppress command line display for the entire batch file?

Choose one answer.

  1. @echo off
  2. @rem
  3. setlocal
#Command Prompt #Batch File #Comment #rem