Skip to content

Truly independent web browser

LibWeb: Import text-wrap-style: balance tests

Andreas Klingc07d59918524
diff --git a/Tests/LibWeb/Crash/wpt-import/css/css-text/crashtests/text-wrap-balance-float-crash.html b/Tests/LibWeb/Crash/wpt-import/css/css-text/crashtests/text-wrap-balance-float-crash.html
new file mode 100644
index 00000000000..a4767b07615
--- /dev/null
+++ b/Tests/LibWeb/Crash/wpt-import/css/css-text/crashtests/text-wrap-balance-float-crash.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<style>
+div {
+ width: 3em;
+ border: thin solid;
+ white-space: balance;
+}
+.float { float: left; }
+</style>
+<div class="float">2</div>
+<div>3</div>
diff --git a/Tests/LibWeb/Crash/wpt-import/css/css-text/crashtests/text-wrap-balance-nested-blocks-crash.html b/Tests/LibWeb/Crash/wpt-import/css/css-text/crashtests/text-wrap-balance-nested-blocks-crash.html
new file mode 100644
index 00000000000..db79cb7d2d6
--- /dev/null
+++ b/Tests/LibWeb/Crash/wpt-import/css/css-text/crashtests/text-wrap-balance-nested-blocks-crash.html
@@ -0,0 +1,365 @@
+<!DOCTYPE html>
+<html lang="en-US">
+<head>
+<meta charset="UTF-8">
+
+<title>Mozilla bug https://bugzilla.mozilla.org/show_bug.cgi?id=1858421</title>
+<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1858421">
+
+<style>
+.main_content { text-wrap: balance; }
+</style>
+
+</head>
+<body>
+<p>
+HTML structure and text content from https://www.contestwatchers.com/international-visual-identity-awards-2024/<br>
+(© 2009 – 2023 Contest Watchers; used by permission, see https://creativecommons.org/licenses/by-sa/3.0/).<br>
+Stripped of styling and external links/resources, purely for testing purposes.
+</p>
+
+ <div>
+ <div class=main_content>
+ <div>
+ <aside>
+ <hr />
+ <div>
+ <div>
+ <a href="#"><span></span><span>Previous</span></a> </div>
+ <article>
+ <div>
+ <h3><a href="#">Reuse the Thermae &#8211; Curinga &#8211; Architecture Competition</a></h3>
+
+<a href="#">
+ <figure>
+
+ <img width="180" height="180" src="." alt="" /> <figcaption>Image source: Reuse Italy</figcaption> </figure>
+ <div><strong>3+ months <span>remaining</span></strong></div> </a>
+ </div>
+</article>
+ </div>
+ <hr />
+ </aside>
+ <div>
+ <div>
+ <article>
+ <header><h1>International Visual Identity Awards 2024</h1></header>
+ <figure>
+ <img width="620" height="380" src="." srcset="." sizes="(max-width: 620px) 100vw, 620px" /> <figcaption>Image source: <strong>International Visual Identity Awards</strong></figcaption>
+ </figure>
+ <div>
+ <aside>
+ <h2>Contest Status</h2>
+ <dl><dt>Deadline</dt><dd><span><strong>30 March 2024</strong></span><span> [ 6+ months remaining ]</span></dd><dt>Results Announcement Expected</dt><dd><span><strong>Summer 2024</strong></span></dd></dl><h2>Contest Disciplines</h2><ul> <li><a href="#">Graphic Design</a></li>
+ </ul> </aside>
+ <aside>
+
+ </aside>
+ <div>
+ <p>Now in their 11th year, the International Visual Identity Awards (IVIA) are a global competition loved by agencies and independent designers.</p>
+<p>With 20 diverse categories, there’s plenty of opportunity to share your branding project with the world. The awards were founded with a clear vision to provide an equal opportunity for all types of entry, from the freelance designer, through to small design studios and larger branding agencies.</p>
+<p>One winner and a second and third place runner-up will be announced in each category. One overall winner receives the title of &#8216;<strong>Visual Identity of the Year</strong>&#8216;.</p>
+<p>The twenty (20) competition categories for 2024 are:</p>
+<ul>
+<li><strong>Manufacturing</strong></li>
+<li><strong>Destination</strong></li>
+<li><strong>Sport</strong></li>
+<li><strong>Entertainment</strong></li>
+<li><strong>Technology</strong></li>
+<li><strong>Telecommunications</strong></li>
+<li><strong>Energy/Utilities</strong></li>
+<li><strong>Consumer products</strong></li>
+<li><strong>Public sector</strong></li>
+<li><strong>Media and publishing</strong></li>
+<li><strong>Transport and automotive</strong></li>
+<li><strong>Healthcare</strong></li>
+<li><strong>Financial services</strong></li>
+<li><strong>Food and drink</strong></li>
+<li><strong>Restaurants, hospitality, travel and leisure</strong></li>
+<li><strong>Retail</strong></li>
+<li><strong>Charity and non-profit</strong></li>
+<li><strong>Professional services</strong></li>
+<li><strong>Fashion</strong></li>
+<li><strong>Real Estate</strong></li>
+</ul>
+<p>Eligible entries must have been launched <strong>between 1st January 2022 and the final closing date</strong>. Entries are permitted from all countries worldwide.</p>
+<p>Entries must include not just a logo but also examples of its application across different items as part of a brand’s visual identity system.</p>
+<p>Winners will be announced in the summer of 2024.</p>
+<p>The International Visual Identity Awards are proudly celebrating their eleventh anniversary this year.</p>
+<h3>International Visual Identity Awards 2024 &#8211; Entry Fee</h3>
+<ul>
+<li>Early Bird Entry Fee: <strong>£135</strong> (+UK VAT where applicable) before 1st December 2023</li>
+<li>Standard Entry Fee: <strong>£150</strong> (+UK VAT where applicable)</li>
+</ul>
+ </div>
+ </div>
+ <footer>
+ <h2>Links and Meta Information</h2>
+ <div>
+ <a href="#">Visit Official Website</a>
+ <h3>Social Sharing Links</h3><ul> <li>
+ <a target="_blank" href="#">
+ <i aria-label="Tweet"></i>
+ </a>
+ </li>
+ <li>
+ <a target="_blank" href="#">
+ <i aria-label="Share on Facebook"></i>
+ </a>
+ </li>
+ <li>
+ <a target="_blank" href="#">
+ <i aria-label="Share on LinkedIn"></i>
+ </a>
+ </li>
+ </ul> </div>
+ <dl><dt>Organizer(s)</dt><dd><a href="#">International Visual Identity Awards</a></dd><dt>Published in</dt><dd><a href="#">Annual</a> / <a href="#">Graphic Design</a> / <a href="#">Open</a></dd><dt>Published after</dt><dd><a href="#">Reuse the Thermae &#8211; Curinga &#8211; Architecture Competition</a></dd><dt>Published before</dt><dd><a href="#">The Golden Sand Waterfront &#8211; TerraViva Competitions</a></dd><dt>Listed on</dt><dd><a href="#">11 October 2023</a></dd><dt>Updated on</dt><dd>11 October 2023</dd><dt>Listed by</dt><dd><a href="#"><span>Contest Watchers</span></a></dd></dl>
+ <fieldset>
+ <legend><label for="cw_short_permalink"><strong>Short permanent link to this page:</strong></label></legend>
+ <input type="text" size="50" readonly="readonly" value="https://www.contestwatchers.com/?p=39783" /></fieldset>
+ </footer>
+ </article>
+ </div>
+ <section>
+ <h2>Possibly Related Contests</h2>
+ <div>
+
+ <article>
+ <div>
+ <h3><a href="#">Curtas Vila do Conde 2024 – International Film Festival</a></h3>
+
+<a href="#">
+ <figure>
+
+ <img width="180" height="180" src="." alt="" loading="lazy" /> <figcaption>Image source: Curtas Vila do Conde</figcaption> </figure>
+ <div><strong>7+ months <span>remaining</span></strong></div> </a>
+ </div>
+</article>
+<article>
+ <div>
+ <h3><a href="#">AMD Design Award 2023: Designing Energy‑Efficient Future</a></h3>
+
+<a href="#">
+ <figure>
+
+ <img width="180" height="180" src="." alt="" loading="lazy" /> <figcaption>Image source: Advanced Micro Devices (AMD)</figcaption> </figure>
+ <div><strong>3+ days <span>remaining</span></strong></div> <span class="cw-free-mark badge
+ bg-success ">Free</span>
+ </a>
+ </div>
+</article>
+<article>
+ <div>
+ <h3><a href="#">Be Izmir Illustration Contest</a></h3>
+
+<a href="#">
+ <figure>
+
+ <img width="180" height="180" src="." alt="" loading="lazy" /> <figcaption>Image source: İzmir Planning Agency (İZPA)</figcaption> </figure>
+ <div><strong>1+ month <span>remaining</span></strong></div> <span class="cw-free-mark badge
+ bg-success ">Free</span>
+ </a>
+ </div>
+</article>
+<article>
+ <div>
+ <h3><a href="#">Andreu World International Design Contest 2023</a></h3>
+
+<a href="#">
+ <figure>
+
+ <img width="180" height="180" src="." alt="" loading="lazy" /> <figcaption>Image source: Andreu World</figcaption> </figure>
+ <div><strong>2+ months <span>remaining</span></strong></div> <span class="cw-free-mark badge
+ bg-success ">Free</span>
+ </a>
+ </div>
+</article>
+ </div>
+ </section>
+ <section>
+ <h2>Other Contests by <a href="#">International Visual Identity Awards</a></h2>
+ <div>
+
+ <article>
+ <div>
+ <h3><a href="#">International Visual Identity Awards 2016 Competition</a></h3>
+
+<a href="#">
+ <figure>
+
+ <img width="180" height="180" src="." alt="" loading="lazy" srcset="." sizes="(max-width: 180px) 100vw, 180px" /> </figure>
+ <div>Expired</div> </a>
+ </div>
+</article>
+<article>
+ <div>
+ <h3><a href="#">International Visual Identity Awards 2022</a></h3>
+
+<a href="#">
+ <figure>
+
+ <img width="180" height="180" src="." alt="" loading="lazy" srcset="." sizes="(max-width: 180px) 100vw, 180px" /> </figure>
+ <div><strong>Finished</strong></div> </a>
+ </div>
+</article>
+<article>
+ <div>
+ <h3><a href="#">International Visual Identity Awards 2020</a></h3>
+
+<a href="#">
+ <figure>
+
+ <img width="180" height="180" src="." alt="" loading="lazy" srcset="." sizes="(max-width: 180px) 100vw, 180px" /> </figure>
+ <div><strong>Finished</strong></div> </a>
+ </div>
+</article>
+<article>
+ <div>
+ <h3><a href="#">International Visual Identity Awards 2023</a></h3>
+
+<a href="#">
+ <figure>
+
+ <img width="180" height="180" src="." alt="" loading="lazy" srcset="." sizes="(max-width: 180px) 100vw, 180px" /> </figure>
+ <div>Expired</div> </a>
+ </div>
+</article>
+ </div>
+ </section>
+ </div>
+ <aside>
+ <hr />
+ <div>
+ <div>
+ <a href="#"><span>Next</span><span></span></a> </div>
+ <article>
+ <div>
+ <h3><a href="#">The Golden Sand Waterfront &#8211; TerraViva Competitions</a></h3>
+
+<a href="#">
+ <figure>
+
+ <img width="180" height="180" src="." alt="" loading="lazy" /> <figcaption>Image source: Adobe Stock</figcaption> </figure>
+ <div><strong>4+ months <span>remaining</span></strong></div> </a>
+ </div>
+</article>
+ </div>
+ <hr />
+ </aside>
+ </div>
+ </div>
+</div>
+<div>
+ <div>
+ <div>
+ <div>
+ <div>
+ <div>
+ <div>
+ <h3>What is Contest Watchers?</h3>
+ <p>Launched in 2009, <a href="#">Contest Watchers</a> is <strong>a website dedicated to creative challenges and competitions worldwide</strong>. With a huge database of international contests in various disciplines, it comes handy to anyone who wants to compete for great prizes and recognition.</p>
+ <p>In a parallel universe, Contest Watchers is a super serious gang of five fictional characters.</p>
+ </div>
+ <div>
+ <h3>Sign up for the Contest Watchers Newsletter</h3>
+ <form>
+ <input type="hidden" name="subscribe" value="subscribe" />
+ <input type="hidden" name="htmlemail" value="1" />
+ <p>Get <strong>all new contests</strong> from Contest Watchers delivered directly to your inbox <strong>daily</strong> or <strong>weekly</strong>.</p>
+ <p>No worries! You can unsubscribe anytime.</p>
+ <div>
+ <input type="email" pattern="^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$" name="email" required="required" placeholder="Your email address">
+ <button type="submit">Sign up</button>
+ </div>
+ <div>
+ <div>
+ <input required checked type="checkbox" value="signup" name="list[2]">
+ <label for="list[2]">
+ Daily Newsletter
+ </label>
+ </div>
+ <div>
+ <input type="checkbox" value="signup" name="list[4]">
+ <label for="list[4]">
+ Weekly Newsletter
+ </label>
+ </div>
+ </div>
+ </form>
+ </div>
+ </div>
+ <div>
+ <div>
+ <div>
+ <div>
+ <div>
+ <h4>Information</h4>
+ <ul>
+ <li><a href="#">About</a></li>
+ <!--<li><a href="">Advertise</a></li>-->
+ <li><a href="#">Contact</a></li>
+ <li><a href="#">RSS Feed</a></li>
+ </ul>
+ </div>
+ <div>
+ <h4>Social Profiles</h4>
+ <ul>
+ <li><a href="#">Twitter</a></li>
+ <li><a href="#">Facebook</a></li>
+ <li><a href="#">LinkedIn</a></li>
+ </ul>
+ </div>
+ </div>
+ </div>
+ <div>
+ <div>
+ <div>
+ <h4>Tools</h4>
+ <ul>
+ <li><a href="#">Suggest Contest</a></li>
+ <li><a href="#">Submit Contest</a></li>
+ <li><a href="#">Network</a></li>
+ </ul>
+ </div>
+ <div>
+ <h4>Goodies</h4>
+ <ul>
+ <li><a href="#" target="_blank">Manage Newsletter Subscriptions</a></li>
+ <li><a href="#">Contests Guide</a></li>
+ <!-- <li><a>Wallpapers</a> (soon)</li> -->
+ <!-- <li><a>Banners</a> (soon)</li> -->
+ </ul>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ <div>
+ <footer>
+ <p>
+ &copy; 2009 &ndash; 2023 <a href="#">Contest Watchers</a>. <a href="#">Some rights reserved</a>. Powered by <a href="#" target="_blank">WordPress</a>.<br />Designed and developed by <a href="#">Goce Mitevski</a>.
+ </p>
+ <ul>
+ <li><a href="#">Privacy Policy</a></li>
+ <li><a href="#">General Disclaimer</a></li>
+ </ul>
+ </footer>
+ <div>
+ <button>
+ <span></span>
+ </button>
+ <button>
+ <span></span>
+ </button>
+</div>
+ </div>
+ </div>
+</div>
+
+</body>
+
+</html>
+
diff --git a/Tests/LibWeb/Crash/wpt-import/css/css-text/white-space/text-wrap-balance-narrow-crash.html b/Tests/LibWeb/Crash/wpt-import/css/css-text/white-space/text-wrap-balance-narrow-crash.html
new file mode 100644
index 00000000000..dcc0d8773df
--- /dev/null
+++ b/Tests/LibWeb/Crash/wpt-import/css/css-text/white-space/text-wrap-balance-narrow-crash.html
@@ -0,0 +1,2 @@
+<!DOCTYPE html>
+<div style="width: 1px; text-wrap: balance">A</div>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-002-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-002-ref.html
new file mode 100644
index 00000000000..74e9fe26e6e
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-002-ref.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<link rel="stylesheet" type="text/css" href="../../../../fonts/ahem.css" />
+<style>
+.container {
+ font-family: Ahem;
+ font-size: 20px;
+ width: 20ch;
+}
+</style>
+<div class="container">
+ 123 567 901 345 789 123
+</div>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-003-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-003-ref.html
new file mode 100644
index 00000000000..9188e6d35c7
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-003-ref.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<link rel="stylesheet" type="text/css" href="../../../../fonts/ahem.css">
+<style>
+div {
+ font: 15px Ahem;
+ width: 35ch;
+ margin: 1em;
+}
+.green {
+ color: green;
+}
+.blue {
+ color: blue;
+}
+</style>
+<p>Both test blocks (green) should have the same layout as the reference (blue):</p>
+<div class="green">The quickest brown fox<br>jumped over the lazy dog</div>
+<div class="green">The quickest brown fox<br>jumped over the lazy dog</div>
+<div class="blue">The quickest brown fox<br>jumped over the lazy dog</div>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-align-001-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-align-001-ref.html
new file mode 100644
index 00000000000..e522e3711c9
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-align-001-ref.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<style>
+.container {
+ font-family: monospace;
+ font-size: 20px;
+ width: 20ch;
+ border: solid 1px;
+}
+</style>
+<div class="container" style="text-align: right">
+ 123456789 123 567
+ 123456789 123 567
+</div>
+<div class="container" style="text-align: center">
+ 123456789 123 567
+ 123456789 123 567
+</div>
+<div class="container" style="text-align: justify">
+ 123456789 123 567
+ 123456789 123 567
+</div>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-before-after-001-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-before-after-001-ref.html
new file mode 100644
index 00000000000..9bf7820c6ab
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-before-after-001-ref.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<style>
+.container {
+ font: 16px monospace;
+ margin: 1em;
+ width: 60ch;
+}
+
+.text1 {
+ text-wrap: balance;
+ margin-bottom: 1em;
+ outline: 1px dashed gray;
+}
+</style>
+
+<p>The two paragraphs should look identical, both having balanced lines:</p>
+
+<div class="container">
+<div class="text1">
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+</div>
+<div class="text1">
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+</div>
+</div>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-dynamic-001-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-dynamic-001-ref.html
new file mode 100644
index 00000000000..43202e4d97f
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-dynamic-001-ref.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<style>
+#container {
+ width: 20ch;
+ text-wrap: balance;
+}
+span:hover {
+ color: red;
+}
+</style>
+<div id="container">
+ 123 567 901 345 789
+ 123 567 901 345 789
+ 123 567 901 345 789
+ 999
+</div>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-line-clamp-001-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-line-clamp-001-ref.html
new file mode 100644
index 00000000000..4e465be7ccf
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-line-clamp-001-ref.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<style>
+.container {
+ font-family: monospace;
+ font-size: 20px;
+ width: 20ch;
+ display: -webkit-box;
+ -webkit-box-orient: vertical;
+ -webkit-line-clamp: 2;
+ overflow: hidden;
+}
+</style>
+<div class="container">
+ 123 567 901 345 789
+ 123 567 901 345 789
+ 123
+</div>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-overflow-001-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-overflow-001-ref.html
new file mode 100644
index 00000000000..64a1cf3d8d5
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-overflow-001-ref.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<style>
+.container {
+ font-family: monospace;
+ font-size: 20px;
+ inline-size: 15ch;
+ border: 1px solid;
+}
+</style>
+<div class="container">CONTROLLING<br>YOUR BU</div>
+<div class="container">CONTROLLING<br>YOUR BU BU</div>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-text-indent-001-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-text-indent-001-ref.html
new file mode 100644
index 00000000000..4b796d5ebb8
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-text-indent-001-ref.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<link rel="stylesheet" type="text/css" href="../../../../fonts/ahem.css" />
+<style>
+div {
+ border: 1px solid;
+ font-family: Ahem;
+ font-size: 10px;
+ text-indent: 5ch;
+ width: 10ch;
+}
+</style>
+<div>
+ 01<br>
+ 34 6 89<br>
+ 12 3 56
+</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/text-wrap-balance-002.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/text-wrap-balance-002.html
new file mode 100644
index 00000000000..997b880b247
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/text-wrap-balance-002.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<link rel="help" href="https://drafts.csswg.org/css-text-4/#valdef-text-wrap-balance">
+<link rel="mismatch" href="../../../../../expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-002-ref.html">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+.container {
+ font-family: Ahem;
+ font-size: 20px;
+ width: 20ch;
+ text-wrap: balance;
+}
+</style>
+<div class="container">
+ 123 567 901 345 789 123
+</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/text-wrap-balance-003.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/text-wrap-balance-003.html
new file mode 100644
index 00000000000..1117c255330
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/text-wrap-balance-003.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<link rel="help" href="https://drafts.csswg.org/css-text-4/#text-wrap-style">
+<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1881855">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-003-ref.html">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css">
+<style>
+div {
+ font: 15px Ahem;
+ width: 35ch;
+ margin: 1em;
+}
+.test {
+ text-wrap: balance;
+ color: green;
+}
+.ref {
+ color: blue;
+}
+</style>
+<p>Both test blocks (green) should have the same layout as the reference (blue):</p>
+<div class="test">The quickest brown fox jumped over the lazy dog</div>
+<!-- inline child elements should not affect wrapping -->
+<div class="test">The <span>quickest <span>brown</span> fox</span> jumped <span>over</span> the <span>lazy dog</span></div>
+<div class="ref">The quickest brown fox<br>jumped over the lazy dog</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/text-wrap-balance-align-001.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/text-wrap-balance-align-001.html
new file mode 100644
index 00000000000..528c86b32d8
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/text-wrap-balance-align-001.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<link rel="help" href="https://drafts.csswg.org/css-text-4/#valdef-text-wrap-balance">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-align-001-ref.html">
+<style>
+.container {
+ font-family: monospace;
+ font-size: 20px;
+ width: 20ch;
+ border: solid 1px;
+ text-wrap: balance;
+}
+</style>
+<div class="container" style="text-align: right">
+ 123456789 123 567
+ 123456789 123 567
+</div>
+<div class="container" style="text-align: center">
+ 123456789 123 567
+ 123456789 123 567
+</div>
+<div class="container" style="text-align: justify">
+ 123456789 123 567
+ 123456789 123 567
+</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/text-wrap-balance-before-after-001.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/text-wrap-balance-before-after-001.html
new file mode 100644
index 00000000000..1c9b0b07586
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/text-wrap-balance-before-after-001.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<link rel="help" href="https://drafts.csswg.org/css-text-4/#valdef-text-wrap-style-balance">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-before-after-001-ref.html">
+<style>
+.container {
+ font: 16px monospace;
+ margin: 1em;
+ width: 60ch;
+}
+
+.text1, .text2 {
+ text-wrap: balance;
+ margin-bottom: 1em;
+ outline: 1px dashed gray;
+}
+
+/* :before and :after pseudos with display:block and no content should not affect
+ the layout of the paragraph content */
+.text2:before, .text2:after {
+ content: "";
+ display: block;
+}
+</style>
+
+<p>The two paragraphs should look identical, both having balanced lines:</p>
+
+<div class="container">
+<div class="text1">
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+</div>
+<div class="text2">
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+</div>
+</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/text-wrap-balance-dynamic-001.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/text-wrap-balance-dynamic-001.html
new file mode 100644
index 00000000000..45399b3851a
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/text-wrap-balance-dynamic-001.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<link rel="help" href="https://drafts.csswg.org/css-text-4/#valdef-text-wrap-balance">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-dynamic-001-ref.html">
+<style>
+#container {
+ width: 20ch;
+ text-wrap: balance;
+}
+span:hover {
+ color: red;
+}
+</style>
+<div id="container">
+ 123 567 901 345 789
+ 123 567 901 345 789
+ 123 567 901 345 789
+</div>
+<script>
+document.body.offsetTop;
+container.appendChild(document.createTextNode('999'));
+</script>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/text-wrap-balance-line-clamp-001.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/text-wrap-balance-line-clamp-001.html
new file mode 100644
index 00000000000..987abdf2f85
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/text-wrap-balance-line-clamp-001.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<link rel="help" href="https://drafts.csswg.org/css-text-4/#valdef-text-wrap-balance">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-line-clamp-001-ref.html">
+<style>
+.container {
+ font-family: monospace;
+ font-size: 20px;
+ width: 20ch;
+ display: -webkit-box;
+ -webkit-box-orient: vertical;
+ -webkit-line-clamp: 2;
+ overflow: hidden;
+ text-wrap: balance;
+}
+</style>
+<div class="container">
+ 123 567 901 345 789
+ 123 567 901 345 789
+ 123
+</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/text-wrap-balance-overflow-001.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/text-wrap-balance-overflow-001.html
new file mode 100644
index 00000000000..2aa18574ae2
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/text-wrap-balance-overflow-001.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<link rel="help" href="https://drafts.csswg.org/css-text-4/#valdef-text-wrap-balance">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-overflow-001-ref.html">
+<style>
+.container {
+ font-family: monospace;
+ font-size: 20px;
+ inline-size: 15ch;
+ border: 1px solid;
+ overflow-wrap: break-word;
+ text-wrap: balance;
+}
+</style>
+<div class="container">CONTROLLING YOUR BU</div>
+<div class="container">CONTROLLING YOUR BU BU</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/text-wrap-balance-text-indent-001.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/text-wrap-balance-text-indent-001.html
new file mode 100644
index 00000000000..4e6e972e4e3
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/text-wrap-balance-text-indent-001.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<link rel="help" href="https://drafts.csswg.org/css-text-4/#valdef-text-wrap-balance">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/white-space/reference/text-wrap-balance-text-indent-001-ref.html">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ border: 1px solid;
+ font-family: Ahem;
+ font-size: 10px;
+ text-indent: 5ch;
+ text-wrap: balance;
+ width: 10ch;
+}
+</style>
+<div>
+ 01
+ 34 6 89
+ 12 3 56
+</div>
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-text/white-space/text-wrap-balance-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-text/white-space/text-wrap-balance-001.txt
new file mode 100644
index 00000000000..29cc82e536d
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-text/white-space/text-wrap-balance-001.txt
@@ -0,0 +1,8 @@
+Harness status: OK
+
+Found 3 tests
+
+3 Pass
+Pass text-wrap-balance-001
+Pass text-wrap-balance-001 1
+Pass text-wrap-balance-001 2
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-text/white-space/text-wrap-balance-right-to-left.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-text/white-space/text-wrap-balance-right-to-left.txt
new file mode 100644
index 00000000000..617978f749e
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-text/white-space/text-wrap-balance-right-to-left.txt
@@ -0,0 +1,8 @@
+Harness status: OK
+
+Found 3 tests
+
+3 Pass
+Pass text-wrap-balance-right-to-left
+Pass text-wrap-balance-right-to-left 1
+Pass text-wrap-balance-right-to-left 2
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-text/white-space/text-wrap-balance-top-to-bottom.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-text/white-space/text-wrap-balance-top-to-bottom.txt
new file mode 100644
index 00000000000..ffb9ca9411d
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-text/white-space/text-wrap-balance-top-to-bottom.txt
@@ -0,0 +1,8 @@
+Harness status: OK
+
+Found 3 tests
+
+3 Pass
+Pass text-wrap-balance-top-to-bottom
+Pass text-wrap-balance-top-to-bottom 1
+Pass text-wrap-balance-top-to-bottom 2
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-text/white-space/text-wrap-balance-001.html b/Tests/LibWeb/Text/input/wpt-import/css/css-text/white-space/text-wrap-balance-001.html
new file mode 100644
index 00000000000..78a96df7123
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-text/white-space/text-wrap-balance-001.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<link rel="help" href="https://drafts.csswg.org/css-text-4/#text-wrap">
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+<style>
+#container {
+ width: 20ch;
+}
+.balance {
+ text-wrap: balance;
+}
+</style>
+<div id="container"></div>
+<script>
+const container = document.getElementById('container');
+for (const text of [
+ 'Balancing should',
+ 'Balancing should not change',
+ 'Balancing should not change the number of lines.',
+ ]) {
+ const normal = document.createElement('div');
+ const balance = document.createElement('div');
+ normal.textContent = text;
+ balance.textContent = text;
+ balance.classList.add('balance');
+ container.appendChild(normal);
+ container.appendChild(balance);
+ test(() => {
+ assert_equals(normal.offsetHeight, balance.offsetHeight);
+ });
+}
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-text/white-space/text-wrap-balance-right-to-left.html b/Tests/LibWeb/Text/input/wpt-import/css/css-text/white-space/text-wrap-balance-right-to-left.html
new file mode 100644
index 00000000000..48bd41a02fd
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-text/white-space/text-wrap-balance-right-to-left.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<link rel="help" href="https://drafts.csswg.org/css-text-4/#text-wrap">
+<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
+
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+<style>
+#container {
+ width: 20ch;
+}
+.balance {
+ text-wrap: balance;
+}
+</style>
+<div id="container" dir="rtl" lang="AR"></div>
+<script>
+const container = document.getElementById('container');
+for (const text of [
+ 'ينبغي تحقيق التوازن',
+ 'يجب ألا تؤدي موازنة التفاف النص إلى تغيير عدد الأسطر',
+ 'يجب ألا تؤدي موازنة التفاف النص إلى تغيير عدد الأسطر لهذه الفقرة النصية',
+ ]) {
+ const normal = document.createElement('div');
+ const balance = document.createElement('div');
+ normal.textContent = text;
+ balance.textContent = text;
+ balance.classList.add('balance');
+ container.appendChild(normal);
+ container.appendChild(balance);
+ test(() => {
+ assert_equals(normal.offsetHeight, balance.offsetHeight);
+ });
+}
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-text/white-space/text-wrap-balance-top-to-bottom.html b/Tests/LibWeb/Text/input/wpt-import/css/css-text/white-space/text-wrap-balance-top-to-bottom.html
new file mode 100644
index 00000000000..11fdd1ee88d
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-text/white-space/text-wrap-balance-top-to-bottom.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<link rel="help" href="https://drafts.csswg.org/css-text-4/#text-wrap">
+<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
+
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+<style>
+#container {
+ height: 15ch;
+ writing-mode: vertical-rl;
+}
+.balance {
+ text-wrap: balance;
+}
+</style>
+<div id="container"></div>
+<script>
+const container = document.getElementById('container');
+for (const text of [
+ '平衡应该',
+ '平衡文本换行不应改变行数',
+ '平衡文本换行不应改变该文本段落的行数',
+ ]) {
+ const normal = document.createElement('div');
+ const balance = document.createElement('div');
+ normal.textContent = text;
+ balance.textContent = text;
+ balance.classList.add('balance');
+ container.appendChild(normal);
+ container.appendChild(balance);
+ test(() => {
+ assert_equals(normal.offsetWidth, balance.offsetWidth);
+ });
+}
+</script>