Yes, Pell grants can be used for online classes. Actually, a higher percentage of the students at online colleges receive Pell awards than those at traditional schools.
But, not every online school is eligible, just as not every bricks and mortar school is either. Use the federal school codes list to check if the school you are thinking about is listed. If you are eligible for a Pell grant, you can use that award at any of the (roughly) 6,000 schools that are approved for federal student financial aid.
If you do not have a particular school in mind, but would like to receive some information about online schools you can use this tool as your starting point. (Click on "more search options" and check "distance learning only" under the extended learning opportunities heading.)