Yes, in most places pool fencing is legally required, though exact rules vary widely by country, state/province, and even city or county, so you must check your specific local building code before building or filling a pool.
General pattern: Most jurisdictions that regulate pools require a barrier — typically a fence at least 4 feet (about 1.2 meters) tall — fully enclosing the pool area, with self-closing, self-latching gates that open outward away from the pool and latches placed high enough (often 54 inches/1.37 m or more) to be out of small children's reach. Many codes also restrict gaps between fence pickets (often no more than 4 inches) and prohibit horizontal footholds that children could climb. Some areas allow alternatives or additions such as pool covers, alarms on doors/windows leading to the pool, or approved automatic pool covers instead of or alongside a fence.
Where rules come from: In the United States, there's no single federal law mandating residential pool fencing nationwide; requirements come from state and local building codes, many of which are based on model codes like the International Swimming Pool and Spa Code (ISPSC) or International Residential Code (IRC), but municipalities can add stricter rules. Some U.S. states and countries (such as Australia, which has notably strict national/state pool safety and fencing laws) mandate fencing for essentially all pools, including above-ground ones, while a few U.S. jurisdictions have looser rules, especially for above-ground pools with locking, removable ladders that limit access.
Practical takeaway: Public pools almost universally require fencing and controlled access. For private/residential pools, always check with your local building or zoning department, homeowners' association, and insurance provider, since requirements can differ even between neighboring towns, and non-compliance can affect legal liability, insurance coverage, and resale of your home.