Updated:

Show a bar in three lines

/bossbar add timer "Time left"
/bossbar set timer players @a
/bossbar set timer color yellow

The first line creates the bar, the second shows it to everyone. A new bar is not visible to anyone until you set players. timer is the bar's ID; use lowercase letters, numbers and _.

Appearance settings

SettingExampleValues
Color/bossbar set timer color redblue, green, pink, purple, red, white, yellow
Style/bossbar set timer style notched_10progress, notched_6, notched_10, notched_12, notched_20
Text/bossbar set timer name "Boss fight"A string or a text component
Visible/bossbar set timer visible falsetrue, false

For colored text use /bossbar set timer name {"text":"Boss fight","color":"red","bold":true}. This form works both before and after the 1.21.5 text format change.

Fill level: max and value

/bossbar set timer max 60
/bossbar set timer value 45

The bar is filled to value ÷ max, so this example is three quarters full. The default max is 100.

A countdown linked to a scoreboard

Count the time in a score and copy it into the bar every tick. This example is a 30-second (600-tick) timer.

Setup (run once):

/scoreboard objectives add time dummy
/scoreboard players set #timer time 600
/bossbar add timer "Time left"
/bossbar set timer max 600
/bossbar set timer players @a

In a repeating command block and a chain command block (always active):

scoreboard players remove #timer time 1
execute store result bossbar timer value run scoreboard players get #timer time

To stop at zero, change the first line to execute if score #timer time matches 1.. run scoreboard players remove #timer time 1.

Players who join later

players @a only adds the players online at that moment. To include players who join later, run bossbar set timer players @a every tick from a repeating command block.

List, check and remove

Common problems

Check your command

The Command Error Doctor checks common syntax mistakes in your browser.