惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
Google DeepMind News
Google DeepMind News
MyScale Blog
MyScale Blog
A
About on SuperTechFans
Martin Fowler
Martin Fowler
M
MIT News - Artificial intelligence
Recent Announcements
Recent Announcements
D
DataBreaches.Net
B
Blog
博客园 - 【当耐特】
爱范儿
爱范儿
有赞技术团队
有赞技术团队
P
Proofpoint News Feed
WordPress大学
WordPress大学
小众软件
小众软件
Apple Machine Learning Research
Apple Machine Learning Research
I
InfoQ
Engineering at Meta
Engineering at Meta
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Last Week in AI
Last Week in AI
Microsoft Azure Blog
Microsoft Azure Blog
雷峰网
雷峰网
量子位
G
Google Developers Blog

Stefan Judis Web Development

Web Weekly #199 Web Weekly #198 Web Weekly #197 Michelle Barker on Stage Fright Web Weekly #196 Escape from Average Web Weekly #195 Web Weekly #194 Web Weekly #193 Web Weekly #192 Web Weekly #191 Web Weekly #190 Web Weekly #189 Web Weekly #188 Intl can localize units, too! The scope of type guards and assertion functions Web Weekly #187 Web Weekly #186 Web Weekly #185 Web Weekly #184 Nobody owes you anything How to scale elements and their layout with CSS "zoom" Notes on relying on the ARIA Authoring Practices Guide Web Weekly #183 Web Weekly #182 How to style the found search / "find in page" substrings Web Weekly #181 Web Weekly #180 ARIA roles can remove their children’s semantics Clean up your Mac with open source
New lines are removed from WHATWG URLs
Stefan Judis · 2026-03-03 · via Stefan Judis Web Development

Published at

Updated at

Reading time
2min

This post is part of my Today I learned series in which I share all my web development learnings.

Today I learned something groundbreaking about URLs!

You know that when you're templating HTML and you're dealing with attribute values, it might make sense to break things into pieces. I like to have one attribute per line and sometimes even break the attribute values into multiple lines.

Long URLs are always tricky, because you can't break these apart...

<a class="something something_else 
          something_very_long something_even_longer"
   href="https://www.example-blog-about-everything-under-the-sun.com/2026/03/03/the-ultimate-comprehensive-and-absolutely-definitive-guide-to-understanding-why-your-css-layout-breaks-at-3am-when-you-least-expect-it-and-how-to-fix-it-once-and-for-all-without-losing-your-sanity-or-your-will-to-live-as-a-frontend-developer-in-the-modern-web-ecosystem-featuring-flexbox-grid-and-container-queries">
  Long link
</a>

Or can you?

Daniel shared that line breaks and tabs will actually be removed from URLs. Excuse me?!

Here's the URL parsing WHATWG spec:

  1. If input contains any ASCII tab or newline, invalid-URL-unit validation error.
  2. Remove all ASCII tab or newline from input.

So, browsers discover newlines or tabs in URLs, recognize them as "invalid-URL-unit" errors, and then remove the invalid characters to get the job done. Nice job, browsers — I love it!

Here's a rendred link including a URL with tabs and newlines for you to inspect.

<a href="https://
web
weekly
.email">
  webweekly.email
</a>

webweekly.email

This link works even when the URL includes new lines and tab characters!

Tabs and newslines are removed and things just work and because we're looking at the WHATWG spec in action here, the characters will be remove in JavaScript, too!

const urlWithTabsAndNewlines = `https://www.	
stefanjudis.
com`;

const normalizedUrl = new URL(urlWithTabsAndNewlines);
console.log(
  normalizedUrl.href === urlWithTabsAndNewlines
); // false

That's pretty wild, isn't it?

Check Daniel's post if you want to learn more!

If you enjoyed this article...

Join 6.5k readers and learn something new every week with Web Weekly.

Stefan standing in the park in front of a green background

Related Topics

Related Articles