Both blueberries and strawberries get their colour from a group of compounds called anthocyanins (Greek anthos "flower "+ kuanos "blue").
Anthocyanins are formed when a sugar such as glucose or galactose combines with a colourless precursor called an anthocyanidin.
The two main anthocyanins are responsible for the colour of strawberries are pelargonin (pelargonidin-3-glucoside) and cyanin (cyanidin-3-glucoside).
An important anthocyanin in blueberries is delphinidin-3-galactoside. Anthocyanins are weak acids. They behave as indicators. They may be red, purple, or blue, depending on the pH.
Like litmus, they are red in acid solutions and blue in basic solutions.
Since strawberries are acidic, their anthocyanins are red. Blueberries are basic, so their anthocyanins are blue.