How to Block a Website in Windows 10

To block a website on your Windows 10 PC, open Notepad as an administrator, open the hosts file in C:\Windows\System32\drivers\etc, and add a line like 0.0.0.0 www.example.com. Save the file, and the site stops loading in every browser on that PC. To unblock it, delete the line.

Applies to: Windows 10. Windows 10 reached end of support on October 14, 2025, and only PCs enrolled in Extended Security Updates still get security fixes, through October 12, 2027.

Block a website with the hosts file

  1. Select Start, type Notepad, right-click it, and select Run as administrator.
  2. Select File > Open, go to C:\Windows\System32\drivers\etc, change Text Documents to All Files, and open hosts.
  3. At the bottom, add one line for each site, like this:

0.0.0.0 www.example.com

  1. Add a second line without www., like 0.0.0.0 example.com, so both versions are blocked.
  2. Select File > Save.
Windows 10 Notepad editing the hosts file with two lines that block www.example.com and example.com
Add a 0.0.0.0 line for each site (1), then save the file (2).
  1. Close and reopen your browser. If the site still opens, run ipconfig /flushdns in Command Prompt.

The file can do more than block sites. Editing the hosts file in Windows 10 covers its other uses.

Unblock a website you blocked

Open the hosts file the same way, delete the line for that site (or type # at the start of it), and save. Then close and reopen your browser.

Windows 10 Command Prompt showing ipconfig /flushdns and a message that the DNS Resolver Cache was flushed
If a change doesn’t show up, run ipconfig /flushdns (1) to clear the old address (2).

Block websites for a child’s account

If you want to filter websites for your kids, use Microsoft Family Safety. Its web filters work in Microsoft’s browser, and you can allow or block sites from the Family Safety website or app once you set up parental controls in Windows 10.

Block several sites at once

Put each address on its own line at the bottom of the hosts file. For example, to block two sites and their www versions, add:

  • 0.0.0.0 example.com
  • 0.0.0.0 www.example.com
  • 0.0.0.0 example.net
  • 0.0.0.0 www.example.net

Using 0.0.0.0 makes the browser fail straight away, while 127.0.0.1 can make it wait a moment first. Either one blocks the site. To keep track, add a note above your entries starting with #, such as # Blocked sites. Windows ignores any line that starts with #.

Check that the block works

  1. Open Command Prompt and run ipconfig /flushdns so Windows forgets the old address.
  2. Close and reopen your browser.
  3. Run ping example.com, using the site you blocked. If the reply comes from 127.0.0.1 or 0.0.0.0, the block is working.
  4. Try opening the site. You should see a “can’t reach this page” error.

The hosts file doesn’t block subdomains automatically, so m.example.com needs its own line too.

If the site still opens

  • Your browser uses its own secure DNS. Some browsers can look up addresses over encrypted DNS. If the block doesn’t work in one browser, turn off its secure DNS setting and test again.
  • A VPN or proxy is on. These can route around your PC’s settings. Disconnect it and test again.
  • The hosts file changed back. Microsoft Defender may treat some hosts file entries, such as ones for popular sites, as unwanted changes and remove them. Check Windows Security > Virus & threat protection > Protection history.
  • The file saved as hosts.txt. In Notepad, set Save as type to All files and make sure the name is just hosts, with no extension.
  • You edited the wrong file. The file must be in C:\Windows\System32\drivers\etc. A copy anywhere else does nothing.

Frequently asked questions

Can I block a website on every device in my home?

Yes, many routers can block websites for the whole network. Look for Parental controls or Access control in your router’s settings.

Can I block an app from the internet instead?

Yes. Windows Defender Firewall can block an application from accessing the internet in Windows 10.

Why can’t I save the hosts file?

Notepad needs to run as an administrator, as in step 1 above. Other ways to run a program as administrator in Windows 10 work too. Some security apps also protect the file.

A website is blocked at work or school. Can I unblock it?

Those blocks are set by the network’s owner. Ask your IT team or teacher if you need access.

Does blocking a site in the hosts file affect other users on the PC?

Yes. The hosts file applies to every account on the computer, which is why you need administrator rights to change it.

Can I block a website in just one browser?

Yes. Browser extensions such as website blockers work in a single browser only. They’re easier to switch off, though, so they suit self-control more than parental controls.

Family Safety web filters are explained in Filter websites and searches using Microsoft Family Safety.

On Windows 11, you can edit the hosts file in Windows 11 the same way or set up parental controls on Windows 11.