How to Block Websites on Windows

The simplest way to block a website on every browser in Windows 10 or 11 is to add it to the hosts file, which tells Windows to send that address nowhere. To block sites for a child’s account, use Microsoft Family Safety instead, but its web filter only works in Microsoft Edge.

You need an administrator account to edit the hosts file.

Block a Website With the Hosts File

  1. Click Start, type Notepad, right-click Notepad and choose Run as administrator.
  2. In Notepad, choose File, Open, and go to C:\Windows\System32\drivers\etc.
  3. Change the file type filter from Text Documents to All Files, then open hosts.
  4. On a new line at the bottom, type 127.0.0.1, a space, and the site name, for example 127.0.0.1 example.com.
  5. Add a second line for the www version: 127.0.0.1 www.example.com.
  6. Save the file (Ctrl+S) and close Notepad.
  7. Open Command Prompt and run ipconfig /flushdns, then restart your browser.
Notepad editing the hosts file with lines that block a website highlighted
Each blocked site needs its own line, with and without www.

To unblock the site later, delete those lines, save, and flush DNS again.

Other Ways to Block Websites

Method Best for Limits
Hosts file Blocking a few sites on one PC, all browsers A browser’s secure DNS setting may bypass it; any admin can undo it
Microsoft Family Safety Children’s Microsoft accounts Web filtering works only in Edge; other browsers are blocked by default when filtering is on
Browser extension One browser only Easy to remove
Router or DNS filtering Every device on your network Setup depends on your router

Block Sites With Microsoft Family Safety

  1. Add the child as a family member at family.microsoft.com and have them sign in to Windows with that account.
  2. Open the family member’s profile and choose Content filters.
  3. Turn on Filter inappropriate websites and searches.
  4. Add sites under Blocked sites, or switch to Only use allowed websites for tighter control.

Troubleshooting

  • Site still opens: flush DNS, close every browser window, and check both the www and non-www lines.
  • Hosts file will not save: Notepad was not opened as administrator, or security software is protecting the file.

Microsoft’s Family Safety guide is at Filter websites and searches using Microsoft Family Safety. Related: changing your DNS server and blocking an IP address in Windows.