Plants have certain processes that keep them alive and help them grow, and different types of plants can have different processes. Weed killers and herbicides can be made to target processes that happen in weeds and not in common grass.
Edit: not all weed killers are like this. They can also be non specific and kind of just kill everything. If you’re buying just be careful on what brand you buy and do some research before you destroy your lawn
Latest Answers