39

I'm currently trying to learn HTML and Java EE Servlet programming. I have an application server running on my local machine (Orion Application Server) and I'm connecting to web pages I've deployed on this server using a browser running on the same machine, directed to http://localhost/mypage.htm (for example).

I know W3C has a site you can go to that will validate an HTML page (and count how many errors are found for a given doctype), but that has to be a publicly available URL. How do you validate HTML on a locally running setup like I've described above?

1

10 Answers 10

33

many options:

see installation of w3c validation service:

http://validator.w3.org/docs/install.html

Firefox addons:

Firefox addon or other tool to locally validate HTML pages

https://addons.mozilla.org/en-US/firefox/addon/249/

Offline validator:

http://htmlhelp.com/tools/validator/offline/index.html.en

2
  • 7
    On Ubuntu/Debian you can just sudo apt-get install w3c-markup-validator May 20, 2013 at 14:42
  • 1
    I found this chrome extension very useful HTML Validator. It can validate a local page by submitting the source to W3C validator
    – mrd3650
    May 14, 2014 at 7:30
13

You can download a vnu.jar release for checking HTML5 documents offline:

https://github.com/validator/validator/releases/download/latest/vnu.jar

Alternatively, you can install it using any of the following:

  • docker run -it --rm -p 8888:8888 ghcr.io/validator/validator:latest
  • npm install vnu-jar
  • brew install vnu
  • pip install html5validator

See https://validator.github.io/validator/ for more details.

5
  • 3
    This is by far the most complete and up-to-date answer to this question as of today. A shame that it doesn't have more upvotes.
    – Clément
    Mar 23, 2016 at 4:07
  • 5
    On Mac, brew install vnu, then vnu path/to/your/file.html.
    – Bluu
    Oct 20, 2016 at 17:47
  • @Bluu please consider also adding a separate answer about the homebrew package to make it more noticeable (I didn’t know about it yet myself…)
    – sideshowbarker
    Oct 21, 2016 at 4:22
  • They also added a "docker" version. "docker run -it --rm -p 8888:8888 ghcr.io/validator/validator:latest" and open a browser to 127.0.0.1:8888
    – txyoji
    Sep 24, 2021 at 21:32
  • @txyoji Thanks — I’ve updated the answer to include that too
    – sideshowbarker
    Sep 24, 2021 at 23:29
7

If you're using firefox, this plugin is perfect:

http://users.skynet.be/mgueury/mozilla/

I use it all day. When you view source it shows you a list of errors and highlights them for you.

5

A command line tool for validating a folder of html files: https://github.com/svenkreiss/html5validator

It integrates with CircleCI and TravisCI and can be used for validating Pelican and Jekyll sites.

2

Perhaps the most straightforward way to do this, is the way I do it all the time. "View source" of the web page, select it all (ctrl+a), choose "copy" (crtl+c), tab over to the validator, and its "direct input" option, and paste it in (ctrl+v). Easy, peasy.

6
  • 1
    What if you have to validate a website with hundreds of pages? Is it still that easy? I run a website where most of the content is generated from TeX by a not-very-reliable Perl script. When I make any changes to the script, I want to be sure I did not break anything.
    – Palec
    Jan 26, 2015 at 10:15
  • If your site has hundreds of pages, it is likely generated by a CMS such as Wordpress, Drupal or such. So all you need to do is validate a random sample of pages, and you are insuring that your CMS-generated pages validate. If you need to validate each and every page, perhaps an automated mechanism is required, but that is neither a) the original question, nor b) the W3C validator.
    – CLWill
    Jan 26, 2015 at 15:24
  • 1
    The original question asked how to validate HTML on local machine, it’s even in the title. You don’t answer that. I gave you an example of site where online validation is not feasible. Hard to guess why exactly the OP wanted the validator to run offline.
    – Palec
    Jan 26, 2015 at 15:38
  • 2
    The OP's question was "the W3C validator assumes a publicly available page", how can I use it to validate something on "localhost"? It does NOT ask "how can I validate pages on my local machine without access to the internet at all". I pointed out a simple, software-free, solution to the question that uses the W3C validator.
    – CLWill
    Jan 26, 2015 at 18:56
  • @CLWill What did you mean by "tab over to the validator"? Did you mean the W3C validator site? Nov 11, 2015 at 5:50
2

On Mac, install w3validator by homebrew brew install vnu. Then check your local site by vnu http://localhost/site or any local file by vnu path/to/your/file.html (From Bluu answer)

1

If you're using node you may use package html-validator

const validator = require('html-validator')
const fs = require('fs')
var options = {
  format: 'text'
}

fs.readFile( 'file-to-validate.html', 'utf8', (err, html) => {
  if (err) {
    throw err;
  }

  options.data = html

  validator(options)
    .then((data) => {
      console.log(data)
    })
    .catch((error) => {
      console.error(error)
    })
})
0

http://validator.w3.org/#validate_by_upload if you don't mind uploading the HTML source file.

http://getfirebug.com/ if you're running Firefox can help with HTML validation issues as well.

0

if you have internet connection and want to use https://validator.w3.org/ for localhost without installing, you can use ngrok

reference : https://academy.byidmore.com/post/W3C-Markup-Validation-for-Localhost-5bc942eb3704302c0986bd60

1
  • 1
    Sounded interesting, but that link is dead
    – mivk
    Oct 25, 2019 at 10:24
0

You can run the tool on your local with docker just by using the command below.

  • docker run -it --rm -p 8888:8888 ghcr.io/validator/validator:latest

After running it with docker, when you go to 127.0.0.1:8888 you will see the validator tool. When you try to validate a url and if you get such an error like IO Error (Connection refused) then you can try installing vnu with brew by using the second command below.

  • brew install vnu

I tried it with docker and I got IO Error. Then I tried it with brew and it was successful. After you install it with brew, now to check a url you should run the command below.

  • vnu http://localhost/page-to-test/

Just replace the url with the one you want to validate with the tool.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.