The Algarve appears to be a large area but is in reality only 160 km long by 40 km wide. Most places are accessible with 90 minutes via the coastal A22 spinal motorway.
Answering your questions as to "Which small towns in the Algarve have the nicest beaches nearby?" depends really on your definition of a small town.
I would suggest that there are two main areas that would be suitable:
1) In the East, around the town of Tavira where there are coastal beaches, beaches on estuaries and on islands a few hundred metres off-shore.
2) In the West, in the area running from Lagos to Sagres and then up the West Coast towards Aljezur/Vale de Telha and Odeceixe.
In this area, you can find:
Meia Praia - a five km long sandy beach skirting Lagos Bay opposite the town of Lagos.
Salema - a one km long beach fronting the picturesque fishing village of Salema, 20 km west of Lagos.
Praia da Zavial - sandy, cliffed line beach 4km from the village of Raposeira on the N 125 and 25 km from Lagos.
Praia da Ingrina - 1 km from Zavial. Small Cove with small beach but delightful.
Sagres - Several beaches tucked into to the cliffs. Warning Access may require climibing up and down 10o steps or more.
Praia Castellano - 25km from Lagos - Accessible via the feeder road that leads out behind the market in the town of Vila de Bispo. Great long cliff-lined beach. Parking can be a hassle in summer or week-ends.
Carrapateira/Bordeira - 35kms from Lagos via Vila de Bispo. Surfer/Sandy Beaches. Carapateira is a small traditional village.
Odeceixe - 45 km from Lagos on the Alentejo Border.
Note there are lots of other small and hidden beaches in this region.
There are also one or two hidden coves between Ferragudo, Carveiro and Armação de Pera but these are becoming fewer in number with development in the area.