Terms like "sense" and "tell" are a bit misleading. It's very much a chemical/mechanical interaction that's automatic. Rather like soap bubbles "sensing" when they've reached the surface of the water.
Plants contain a protein called phototropin, which is activated by light. When it's activated, it changes the shape and alignment of the "skeleton" of the cell, making it more cube-shaped as opposed to long and skinny.
That means the light side of a plant gets shorter, while the dark side remains long. The dark side also grows slightly faster, on a count of having more cells there (you can fit more skinny cells side-by-side than wide cells), and so the plant angles and grows toward the light.
And yes. The colour matters. Phototropin reacts best to blue light, and leaves absorb mostly red and blue light (which is why they're green). It basically ignores the green light filtered through leaves.