HTML Guides for space
Learn how to identify and fix common HTML validation errors flagged by the W3C Validator — so your pages are standards-compliant and render correctly across every browser. Also check our Accessibility Guides.
This mailto: link has a space somewhere in its address, and a URL can't contain a raw space.
The validator says the space comes "after ilto:", which means anywhere after the scheme, not only right after the colon. It flags a space typed after mailto:, a space inside the address, a space after the comma between two recipients, and text or markup left in the attribute after the address, such as mailto:info@example.com <br>. That last case shows up when a template or CMS field drops HTML into the link.
A mailto: URL, defined in RFC 6068, holds one or more bare email addresses after the colon. Some browsers open the mail client anyway, but the extra text can end up in the recipient field.
A space inside the subject or body parameters triggers a different message, "Illegal character in query". Encode those spaces as %20.
To fix it, remove the spaces and anything after the address that isn't part of it. Separate several recipients with a comma and no space.
Invalid example
<a href="mailto: info@example.com">Email us</a>
<a href="mailto:info@example.com, sales@example.com">Email us</a>
<a href="mailto:info@example.com <br>">Email us</a>
Valid example
<a href="mailto:info@example.com">Email us</a>
<a href="mailto:info@example.com,sales@example.com">Email us</a>
The URL in this link has a space in its port number, and a port can only contain digits.
In a URL such as https://example.com:8080/, the part after the colon that follows the host is the port. The URL Standard allows only digits there, up to the next /, ? or #. When the parser meets a space before that point, it gives up on the whole URL. A browser can't follow a link it can't parse, so clicking it does nothing.
The usual cause is a phone link written as http://tel: followed by a number with spaces between the digit groups, like http://tel:555 123 4567. The parser reads tel as a host name and the phone number as its port, then fails at the first space. Removing the spaces doesn't help. The link would point at a web server called tel, and most phone numbers are larger than 65535, the highest port allowed.
Phone links use the tel: scheme on its own, with no http:// in front, as defined in RFC 3966. A tel: URL can't contain spaces either, so write the digits together, starting with + and the country code. To keep the number easy to read, put the spaced version in the link text.
When the URL really has a port, the space is usually a typo or whitespace left by a template, as in https://example.com:8080 /reports. Delete it.
Invalid example
<p>Call us at <a href="http://tel:555 123 4567">555 123 4567</a>.</p>
<a href="https://example.com:8080 /reports">Open the reports</a>
Valid example
<p>Call us at <a href="tel:+15551234567">+1 555 123 4567</a>.</p>
<a href="https://example.com:8080/reports">Open the reports</a>
A URL is made up of several parts: scheme, host (domain), path, query, and fragment. While some of these parts allow certain special characters (often percent-encoded), the host portion has strict rules. Domain names follow the DNS naming conventions, which only permit ASCII letters (a-z, A-Z), digits (0-9), hyphens (-), and dots (.) as label separators. Spaces are categorically forbidden.
This validation error typically occurs in two scenarios:
- A literal space appears in the domain, e.g.,
http://my domain.com. This is often a typo or a copy-paste error. - A percent-encoded space (
%20) appears in the domain, e.g.,http://my%20domain.com. While%20is valid in URL paths and query strings, it is not valid in the host portion. Percent-encoding does not make a space legal in a domain name — it still resolves to a space character, which DNS cannot handle.
Why this is a problem
- Broken links: Browsers cannot resolve a domain with spaces to an actual server. Users clicking the link will get an error or be taken nowhere.
- Accessibility: Screen readers and assistive technologies may announce the link, but users will encounter a dead end, creating a frustrating experience.
- Standards compliance: The WHATWG URL Standard explicitly forbids spaces in the host component. The W3C validator flags this to help you catch what is almost certainly a mistake.
- SEO impact: Search engine crawlers will treat the URL as invalid and will not follow or index it.
How to fix it
- Check for typos: The most common fix is to correct the domain to the actual, valid domain name you intended.
- Replace spaces with hyphens: If the intended domain genuinely has a word separator, the standard convention is to use hyphens (e.g.,
my-domain.com). - Remove spaces entirely: Sometimes spaces are accidentally introduced and simply need to be removed (e.g.,
mydomain.com). - Check the path vs. host: If the space belongs in a file path or query parameter rather than the domain, make sure it's in the correct part of the URL and properly percent-encoded there.
Examples
❌ Literal space in the domain
<a href="http://my domain.com/page">Visit site</a>
❌ Percent-encoded space in the domain
<a href="http://my%20domain.com/page">Visit site</a>
✅ Fixed: use a hyphen in the domain
<a href="http://my-domain.com/page">Visit site</a>
✅ Fixed: remove the space entirely
<a href="http://mydomain.com/page">Visit site</a>
✅ Spaces are fine in the path (percent-encoded)
Note that %20 is valid in the path portion of a URL — just not in the domain:
<a href="http://mydomain.com/my%20page">Visit page</a>
Common mistake: space before or after the domain
Sometimes the space is hard to spot because it's at the beginning or end of the URL, or between the scheme and domain:
<!-- ❌ Trailing space in domain -->
<a href="http://mydomain.com /page">Visit site</a>
<!-- ✅ Fixed -->
<a href="http://mydomain.com/page">Visit site</a>
If your URLs are generated dynamically (e.g., from a CMS or database), make sure to trim whitespace from the domain portion before constructing the full URL. A quick way to catch these issues during development is to validate your HTML regularly with the W3C Markup Validation Service.
The HTML specification requires that attributes on an element be separated by one or more ASCII whitespace characters. When you omit the space — typically between a closing quote of one attribute's value and the name of the next attribute — the browser may struggle to determine where one attribute ends and the next begins. While some browsers may attempt to parse the element correctly, the behavior is not guaranteed and can lead to unexpected results.
This issue commonly occurs when editing HTML by hand, especially when copying and pasting attributes from different sources or when a template engine concatenates attribute strings without proper spacing. It can also happen when a closing quote is immediately followed by another attribute name, making the markup difficult to read and maintain.
Beyond validation, missing spaces between attributes hurt code readability. Other developers (or your future self) scanning the markup may misread attribute boundaries, leading to bugs that are hard to track down. Consistent spacing also ensures that assistive technologies and browser parsers interpret your elements exactly as intended.
How to Fix It
Go through your HTML and ensure every attribute is separated from adjacent attributes by at least one space character. Pay special attention to:
- Attributes placed immediately after a quoted value (e.g.,
"value"classshould be"value" class). - Attributes placed after unquoted values, which can be even more ambiguous.
- Dynamically generated markup from template engines or JavaScript, where concatenation might drop whitespace.
Examples
Incorrect: No Space Between Attributes
<a href="page.php"class="big">link</a>
Here, class is placed directly after the closing quote of the href value with no space in between. The validator will flag this as an error.
Correct: Space Between Attributes
<a href="page.php" class="big">link</a>
A single space between "page.php" and class resolves the issue.
Incorrect: Multiple Missing Spaces
<img src="photo.jpg"alt="A sunset"width="600"height="400">
All four attributes run together without any whitespace separating them.
Correct: All Attributes Properly Spaced
<img src="photo.jpg" alt="A sunset" width="600" height="400">
Correct: Using Line Breaks as Whitespace
When an element has many attributes, you can use newlines for separation, which also improves readability:
<img
src="photo.jpg"
alt="A sunset"
width="600"
height="400">
Newlines and indentation count as valid whitespace between attributes and are perfectly acceptable in HTML. This multi-line style is especially helpful for elements with numerous attributes, such as <input> fields in forms or components with data attributes.
Validate at scale.
Ship accessible websites, faster.
Automated HTML & accessibility validation for large sites. Check thousands of pages against WCAG guidelines and W3C standards in minutes, not days.
1K Weekly
1,000 monthly checks. Cancel anytime.
Get 1K Weekly →Join teams across 40+ countries