HTML Checking for Large Sites
Rocket Validator automatically checks your pages on the W3C Validator.
An “img” element which has an “alt” attribute whose value is the empty string must not have a “role” attribute.
When an img
element has an empty alt
attribute, its role is implicitly decorative, so it must not specify a role
attribute.
Learn more:
Related W3C validator issues
There can only be one visible <main>
element in a document. If more are needed (for example for switching between them with JavaScript), only one can be visible, the others should be hidden toggling the hidden
attribute.
Example of 2 main
elements, where only one is visible:
<main>
<h1>Active main element</h1>
<!-- content -->
</main>
<main hidden>
<h1>Hidden main element</h1>
<!-- content -->
</main>
Learn more:
Elements with the role tab
must either be a child of an element with the tablist
role, or have their id
part of the aria-owns
property of a tablist
.
An element with the tab role controls the visibility of an associated element with the tabpanel role. The common user experience pattern is a group of visual tabs above, or to the side of, a content area, and selecting a different tab changes the content and makes the selected tab more prominent than the other tabs.
Example:
<div class="tabs">
<div role="tablist" aria-label="Sample Tabs">
<button role="tab" aria-selected="true" aria-controls="panel-1" id="tab-1" tabindex="0">
First Tab
</button>
<button role="tab" aria-selected="false" aria-controls="panel-2" id="tab-2" tabindex="-1">
Second Tab
</button>
</div>
<div id="panel-1" role="tabpanel" tabindex="0" aria-labelledby="tab-1">
<p>Content for the first panel</p>
</div>
<div id="panel-2" role="tabpanel" tabindex="0" aria-labelledby="tab-2" hidden>
<p>Content for the second panel</p>
</div>
</div>
Learn more at:
A button
element, or an element with the role=button
attribute, is not allowed to be nested inside an <a>
element.
<img>
tags, used to include images on a document, require an alt
attribute to describe the contents of the image. This is essential for users that cannot see the image (like screen reader users), or as an alternate text when the image cannot be displayed. Example:
<img src="photo.jpg" alt="Person holding a cat" />
A start tag for <img>
has been found inside a <noscript>
section within the <head>
, where it’s not allowed. Consider moving it to the <body>
section.
The HTML <noscript>
element defines a section of HTML to be inserted if a script type on the page is unsupported or if scripting is currently turned off in the browser.
When JavaScript is disabled, the content inside <noscript>
will be used instead, so this content must fit within its parent section. As an <img>
tag is not allowed inside <head>
, this will raise an issue. Instead, consider moving the <noscript>
part to the <body>
section.
This issue is often related to 3rd party tracking pixels like the Facebook or LinkedIn conversion tracking pixels. For example, the Facebook pixel instructions tell you to insert it like this:
<html>
<head>
<script>
...some script...
</script>
<noscript>
<img src="..." />
</noscript>
</head>
<body>
...
</body>
</html>
Instead, consider moving the <noscript>
part inside the <body>
, where the <img>
makes sense to be inserted:
<html>
<head>
<script>
...some script...
</script>
</head>
<body>
...
<noscript>
<img src="..." />
</noscript>
</body>
</html>
Learn more:
The alert
role can be used to tell the user an element has been dynamically updated. Screen readers will instantly start reading out the updated content when the role is added. The element <ul>
doesn’t accept this kind of role, consider using other element like <p>
or <div>
.
The alert role is used to communicate an important and usually time-sensitive message to the user. When this role is added to an element, the browser will send out an accessible alert event to assistive technology products which can then notify the user about it. The alert role is most useful for information that requires the user’s immediate attention.
Learn more about the alert
ARIA role:
A <li>
element, used to define a list item, does not accept the button
role.
This HTML code is invalid because the <li>
elements can’t have role="button"
:
<ul>
<li role="button">One</li>
<li role="button">Two</li>
</ul>
Learn more:
The src
attribute on an <img>
element contains an invalid character, that should be properly encoded as a URI percent-encoded character.
Learn more:
The src
attribute for <img>
tags is required, to define the source of the image, like in this example:
<img src="photo.jpg" alt="wombat" />
The attributes width
and height
of <img>
elements expect a non-negative integer, so an empty string is not allowed. Either define the correct dimension, or remove this attribute.
Learn more:
<input>
elements can’t have a search
role. Instead, try with <input type="search">
.
<input>
elements of type search
are text fields designed for the user to enter search queries into. These are functionally identical to text inputs, but may be styled differently depending on the user agent.
The search
role is a landmark. Landmarks can be used by assistive technology to quickly identify and navigate to large sections of the document. The search role is added to the container element that encompasses the items and objects that, as a whole, combine to create search functionality. When a <form>
is a search form, use the search
role on the form
.
Example of a search form:
<form role="search">
<label for="search-input">Search this site</label>
<input type="search" id="search-input" name="search">
<input value="Submit" type="submit">
</form>
Learn more:
The src
attribute on an element <img>
contains a {
curly bracket character, which is not allowed unless properly encoded.
Space characters are not allowed in src
attributes. Instead, they should be converted to %20
. In this example, the first line is invalid and the second is valid:
<img src="https://example.com/?s=some term" alt="description" />
<img src="https://example.com/?s=some%20term" alt="description" />
The src
attribute on an element <img>
contains a character that is not allowed, and should be encoded.
Some typical examples include the pipe character |
that should be replaced by its encoded alternative %7C
, and the left square bracket [
that needs to be encoded as %5B
.
The src
attribute on an <img>
tag is not allowed to contain space characters. You should replace them with “%20
“.
The attributes width
and height
on <img>
elements define the dimensions of the image in CSS pixels, and expect a non-negative integer.
Learn more:
<img>
elements accept a width
attribute to specify the size in pixels. This value can only be an integer, it should not contain units or %
. If you need to specify a percentage width, you can do that with CSS:
<img src="photo.jpg" alt="red car" style="width:100%;">
The width
and height
attributes on <img>
and <iframe>
elements expect a digit to indicate the number of pixels. Ensure that this attribute contains only digits.
For example:
<!-- This is invalid because width is not a digit -->
<img width="225px" height="100px" alt="cat" src="cat.jpg" />
<!-- This is valid -->
<img width="225" height="100" alt="cat" src="cat.jpg" />
The <a>
element requires either a href
attribute, or a role
attribute.
Learn more:
<img>
tags used to display images require the attribute src
to indicate the source of the image, for example <img src="/img/photo.jpg" />
.
An element is using ARIA attributes, but its role
has not been defined. ARIA defines semantics that can be applied to elements, with these divided into roles (defining a type of user interface element) and states and properties that are supported by a role. Authors must assign an ARIA role and the appropriate states and properties to an element during its life-cycle, unless the element already has appropriate ARIA semantics (via use of an appropriate HTML element). Examples:
<!-- This div uses ARIA but its role is not clear, so it's invalid. -->
<div aria-expanded="true">...</div>
<!-- This div defines clearly its role, so it's valid. -->
<div role="navigation" aria-expanded="true">...</div>
<!-- Nav elements have an implicit navigation role so we don't need the role attribute. -->
<nav aria-expanded="true">...</nav>
Read about Using ARIA: Roles, states and properties.
The article
role indicates a section of a page that could easily stand on its own on a page, in a document, or on a website, is implicit when using the <article>
tag.
This role indicates a section of a page that could easily stand on its own on a page, in a document, or on a website. It is usually set on related content items such as comments, forum posts, newspaper articles or other items grouped together on one page. It can be added to generic elements like <div>
to convey this role, for example:
<div role="article">
<h2>Heading</h2>
<p>Content...</p>
</div>
Instead of using this role, it’s preferrable to use the native <article>
element like this:
<article>
<h2>Heading</h2>
<p>Content...</p>
</article>
Learn more:
The <header>
HTML element represents introductory content, typically a group of introductory or navigational aids, and has an implicit role of banner
, so specifying this role is redundant.
The following example represents a banner using the role
attribute:
<div role="banner">
<img src="companylogo.svg" alt="my company name" />
<h1>Title</h1>
<p>Subtitle</p>
</div>
By default, the HTML5 <header>
element has an identical meaning to the banner landmark, unless it is a descendant of <aside>
, <article>
, <main>
, <nav>
, or <section>
, at which point <header>
is the heading for that section and not the equivalent of the site-wide banner.
This example uses the <header>
element instead of the banner
role:
<header>
<img src="companylogo.svg" alt="my company name" />
<h1>Title</h1>
<p>Subtitle</p>
</header>
<img>
tags no longer accept a border
attribute. This can be defined using CSS instead, for example:
<img src="..." alt="..." style="border:0;" />
The button
role is used to make an element appear as a button control to a screen reader and can be applied to otherwise non-interactive elements like <div>
. If you’re already using a <button>
element, then it’s redundant to apply it the role button
, as that’s implicit.
<!-- Instead of this -->
<button role="button">Buy</button>
<!-- Do this -->
<button>Buy</button>
Learn more:
The <summary>
HTML element specifies a clickable summary, caption, or legend for a <details>
element’s disclosure box. As the <summary>
element has an implicit button
role, it’s not needed to include it explicitly.
Here’s an example, clicking the <summary> element toggles the state of the parent <details> element open and closed.
<details>
<summary>I have keys but no doors. I have space but no room. You can enter but can’t leave. What am I?</summary>
A keyboard.
</details>
Learn more:
Using the <aside>
element will automatically communicate a section has a role of complementary
, so specifying the role="complementary"
is redundant.
The <footer>
element represents a footer for its nearest sectioning content, and has an implicit role of contentinfo
, so specifying this role is redundant.
The following example marks a <div>
as a footer specifying its role:
<div role="contentinfo">
<h2>Footer</h2>
<!-- footer content -->
</div>
Using the <footer>
element instead is recommended:
<footer>
<h2>Footer</h2>
<!-- footer content -->
</footer>
Lear more:
MDN: ARIA contentinfo role MDN: footer * HTML Spec: the footer element
A <form>
element has already a form
role, so specifying role="form"
in it is redundant.
Instead of:
<form role="form">
You can simply write:
<form>
The heading
role defines this element as a heading to a page or section, and is implicit in tags <h1>
to <h6>
.
The heading
role indicates to assistive technologies that this element should be treated like a heading. Screen readers would read the text and indicate that it is formatted like a heading.
This ARIA role is only needed to add that role to a generic element like <div>
, for example:
<div role="heading" aria-level="1">This is a main page heading</div>
This defines the text in the <div>
to be the main heading of the page, indicated by being level 1 via the aria-level
attribute. Opt for using the <h1>
(thru <h6>
) element instead:
<h1>This is a main page heading</h1>
Learn more:
A single <img>
element is used to embed an image, so adding the img
role to it is redundant.
The ARIA img role can be used to identify multiple elements inside page content that should be considered as a single image. These elements could be images, code snippets, text, emojis, or other content that can be combined to deliver information in a visual manner, for example:
<div role="img" aria-label="Description of the overall image">
<img src="graphic1.png" alt="">
<img src="graphic2.png">
</div>
Learn more:
A <li>
element is used to define an item of a list, so adding the listitem
role to it is redundant.
The ARIA listitem
role can be used to identify an item inside a list of items. It is normally used in conjunction with the list
role, which is used to identify a list container.
<section role="list">
<div role="listitem">List item 1</div>
<div role="listitem">List item 2</div>
<div role="listitem">List item 3</div>
</section>
When possible, you should use the appropriate semantic HTML elements to mark up a list and its list items — <ul>
or <ol>
, and <li>
. For example:
<ul>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
</ul>
Read more:
The main
landmark role is used to indicate the primary content of a document. It can be added to an element by using role="main"
, but instead it’s preferable to just use the <main>
element. In that case, it’s unnecessary to make the main role explicit. Examples:
<div role="main">
<!-- this is a valid way to define a main role -->
</div>
<main>
<!-- but this is shorter and uses correct semantic HTML -->
</main>
Read more:
The navigation
landmark role is used to identify major groups of links used for navigating through a website or page content. It can be added to an element that contains navigation links by using role="navigation"
, but instead it’s preferable to just use the <nav>
element. In that case, it’s unnecessary to make the navigation role explicit.
Examples:
<div role="navigation">
<!-- this is a valid way to define a navigation role -->
</div>
<nav>
<!-- but this is shorter and uses correct semantic HTML -->
</nav>
Read more about the nav element and the ARIA Navigation Role.
The textbox
role, used to identify an element that allows the input of free-form text, is unnecessary for an <input>
element of type text
when it doesn’t have a list
attribute.
Learn more:
Check the HTMLImageElement.srcset guide to learn about the correct usage of the srcset
and sizes
attributes.
Still checking your large sites one page at a time?
Save time using our automated web checker. Let our crawler check your web pages on the W3C Validator.