Trailer brakes work by activating a magnetic brake when the trailer receives a signal from the vehicle towing it. Simple trailers typically don't have brakes, but those that do must be attached to a vehicle with appropriate equipment.
Because creating a mechanical connection to a trailer would be cumbersome, trailers with brakes use electrical braking. When the driver presses the brake pedal, the vehicle sends an electrical signal to the brake which activates a magnet. When the magnet moves toward the drum's face, it begins to rotate, which pushes the two shoes down to the drum. This creates friction, which slows down the wheel hub.
How a trailer brakes depends largely on the vehicle's brake controller. The trailer brakes simply respond to the electricity they receive, but different types of controllers have different operating profiles. Proportional brake controllers detect the speed of the vehicle and brake the trailer at approximately the same speed as the vehicle; this reduces wear on the vehicle's and trailer's brake systems and leads to a smooth experience.
Pendulum brake systems detect vehicle braking using a pendulum and signal the trailer's brakes when the pendulum moves forward. Time-delay brake systems require the driver to set a delay based on how much weight the trailer is carrying and typically lead to more wear on the brakes, but their lower operating costs make them a viable option in some cases.