Qbasic Color statement

Qbasic Color statement is used to change the Foreground and the background color of the Text in the QBasic Program. The Syntax of COLOR statement is:

 COLOR foreground, background

The word foreground means the color of the text and background color means the background color behind the text.

You can use the COLOR statement in Qbasic in the following ways:

1) To modify both foreground and background color:

SYNTAX: COLOR [foreground color] , [background color]

Use a comma to separate the foreground and the background color.



COLOR 14, 1

PRINT Yellow text with blue background

2) To change the foreground color only:

SYNTAX: COLOR [foreground]




PRINT “This is the green text”

3) To change only the background-color

SYNTAX: COLOR , [background]

Use a comma after the COLOR command and then your background color code



PRINT “this is the blue background”

To change the entire background color of your screen, use CLS (clear screen) command after setting the background color.



COLOR 14, 1
PRINT “Yellow text with entire screen blue background”

The foreground and the background color are represented by numbers in Qbasic. You can use the qbasic color codes to change the color according to your preferences:

Qbasic Color code table

There are 16 colors (in screen mode 0), numbered from 0 to 15.

You can see from the color code table that there are 8 main colors(from 0 to 7), and the color from 8 to 15 are just the repetitions of color from 1 to 7 but in a lighter shade. The colors are a combination of binary values (blue = 1, green = 2, red = 4), which makes it easier to memorize the color codes.

If you want blinking color, it is available from color code 16 to 31. At 16, the color starts again with blicking black color and ends with blinking white at 31. The blinking option is not available for the background, it only works for the foreground color(text color). Here the example how to get the blinking color code = 2 (green color code ) + 16 = 18( blinking green color), 4(red color code) + 16 = 20 (blinking red color).

Related Articles:

Qbasic Control Statements with Examples

Download Qbasic (QB64) Free for Windows 10 and 11

Qbasic Programming Examples and Exercises

Qbasic Looping statements with Examples

Free QBasic Online Compilers – Online Editors

QBASIC Programming – Beginner’s Friendly

Scroll to Top