There are quite a few legal requirements when it comes to bikw lights. If you do not comply with these, you risk a fine. Which makes sense, because without proper bicycle lighting, you are a danger to yourself and others. Roughly speaking, you must have your lights on between sunset and sunrise. You just must not inconvenience other road users with your bike lights. The official rules differ from country to country, but generally include:
Between sunset and sunrise, you must have bike lights on your bike.
In fog or other situations where you have poor visibility, bike lights should also be lit.
Your rear light must be red and your front light must be white or yellow.
Your bike lights must be clearly visible, i.e. not obstructed by a bike basket or pannier bag.
You may have a maximum of 1 front light and 1 rear light.
Bicycle lights must not flash.