Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you know a HTML-Snippet Validator?

I'm searching for a tool that would allow me to check whether a certain snippet of HTML would be valid in it's proper context.

I'd input something like

<dd>     my definition      <div>         div inside &lt;dd&gt; is allowed     </div> </dd> 

instead of the whole document. A ordinary validator will complain about the missing dl-tag, but most of the times I just want to know whether a certain element is valid inside another one or not.


I'll try to explain it more detailed. Consider the following snippet:

<form>     <label>Name: <input /></label> </form> 

Would be valid, but to check it I have two options:

  1. Validate the whole document: Most of the times this is good enough, but sometimes when I'm working on partial HTML snippets or embedded HTML it's quite some trouble. I'd have to copy the whole thing to a new HTML document and validate that.
  2. Just copy the snippet and validate it with the W3C validator and ignore some of the errors.

Basically I'd like to check, whether an element contains only elements it's allowed to contain.

like image 608
Kevin Smith Avatar asked Nov 09 '11 06:11

Kevin Smith


People also ask

What does a HTML Validator do?

An HTML validator is a quality assurance program used to check Hypertext Markup Language ( HTML ) markup elements for syntax errors. A validator can be a useful tool for an HTML user who receives data electronically from a variety of input sources.

How do you check if a HTML is valid?

The World Wide Web Consortium provide a simple online tool (https://validator.w3.org/) that automatically check your HTML code and point out any problems/errors your code might have, such as missing closing tags or missing quotes around attributes.

Should I use an HTML validator?

In Summary. Validating any HTML you write as you build your websites will take the guesswork out of how the different browser rendering engines might render your website. This will help you to reduce the amount of time you spend debugging problems with your markup.


Video Answer


1 Answers

You can actually use the W3C validator to check a snippet.

Choose the 'Validate by Direct Input' tab and select More Options. In there there is a radio button to 'Validate HTML fragment'. http://validator.w3.org/#validate_by_input+with_options

It will wrap your page in valid html so the errors which you see are only due to your snippet.

like image 136
extols Avatar answered Sep 25 '22 12:09

extols