Similar color groups for HTML

I start my adventure as a front end developer and I wonder about the easiest way to choose the color groups used in css for my projects. For example, I have a group of grayscale colors. How large should the "distances" between them be (assuming that they are placed on top of each other eg text on the background) to ensure good visibility? Is there any universal method to determine this?