diff --git a/routers/web/repo/wiki_test.go b/routers/web/repo/wiki_test.go
index 00a35a5da0..47bad6d8e0 100644
--- a/routers/web/repo/wiki_test.go
+++ b/routers/web/repo/wiki_test.go
@@ -86,7 +86,7 @@ func TestWiki(t *testing.T) {
 	Wiki(ctx)
 	assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
 	assert.EqualValues(t, "Home", ctx.Data["Title"])
-	assertPagesMetas(t, []string{"Home", "Page With Image", "Page With Spaced Name", "Unescaped File"}, ctx.Data["Pages"])
+	assertPagesMetas(t, []string{"Home", "Long Page", "Page With Image", "Page With Spaced Name", "Unescaped File"}, ctx.Data["Pages"])
 }
 
 func TestWikiPages(t *testing.T) {
@@ -96,7 +96,7 @@ func TestWikiPages(t *testing.T) {
 	contexttest.LoadRepo(t, ctx, 1)
 	WikiPages(ctx)
 	assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
-	assertPagesMetas(t, []string{"Home", "Page With Image", "Page With Spaced Name", "Unescaped File"}, ctx.Data["Pages"])
+	assertPagesMetas(t, []string{"Home", "Long Page", "Page With Image", "Page With Spaced Name", "Unescaped File"}, ctx.Data["Pages"])
 }
 
 func TestNewWiki(t *testing.T) {
diff --git a/templates/repo/wiki/search.tmpl b/templates/repo/wiki/search.tmpl
index 1b774908d0..7f4cb9c5a2 100644
--- a/templates/repo/wiki/search.tmpl
+++ b/templates/repo/wiki/search.tmpl
@@ -1,6 +1,6 @@
 {{if .Results}}
 	{{range .Results}}
-		<a class="item tw-max-w-[80vw]" href="{{$.RepoLink}}/wiki/{{.Filename}}">
+		<a class="item tw-max-w-[min(80vw,calc(0.8*var(--container-width)))]" href="{{$.RepoLink}}/wiki/{{.Filename}}">
 			<b class="tw-block tw-mb-2 tw-whitespace-break-spaces">{{.Title}}</b>
 			{{range .LineCodes}}
 				<p class="tw-my-0 tw-whitespace-break-spaces">{{.}}</p>
diff --git a/tests/e2e/repo-wiki.test.e2e.ts b/tests/e2e/repo-wiki.test.e2e.ts
index c1b48dabf2..f32fe3fc91 100644
--- a/tests/e2e/repo-wiki.test.e2e.ts
+++ b/tests/e2e/repo-wiki.test.e2e.ts
@@ -6,17 +6,26 @@
 import {expect} from '@playwright/test';
 import {test} from './utils_e2e.ts';
 
-test(`Search for long titles and test for no overflow`, async ({page}, workerInfo) => {
-  test.skip(workerInfo.project.name === 'Mobile Safari', 'Fails as always, see https://codeberg.org/forgejo/forgejo/pulls/5326#issuecomment-2313275');
-  await page.goto('/user2/repo1/wiki');
-  await page.getByPlaceholder('Search wiki').fill('spaces');
-  await page.getByPlaceholder('Search wiki').click();
-  // workaround: HTMX listens on keyup events, playwright's fill only triggers the input event
-  // so we manually "type" the last letter
-  await page.getByPlaceholder('Search wiki').dispatchEvent('keyup');
-  // timeout is necessary because HTMX search could be slow
-  await expect(page.locator('#wiki-search a[href]')).toBeInViewport({ratio: 1});
-});
+for (const searchTerm of ['space', 'consectetur']) {
+  for (const width of [null, 2560, 4000]) {
+    test(`Search for '${searchTerm}' and test for no overflow ${width && `on ${width}-wide viewport` || ''}`, async ({page, viewport}, workerInfo) => {
+      test.skip(workerInfo.project.name === 'Mobile Safari', 'Fails as always, see https://codeberg.org/forgejo/forgejo/pulls/5326#issuecomment-2313275');
+
+      await page.setViewportSize({
+        width: width ?? viewport.width,
+        height: 1440, // We're testing that we fit horizontally - vertical scrolling is fine.
+      });
+      await page.goto('/user2/repo1/wiki');
+      await page.getByPlaceholder('Search wiki').fill(searchTerm);
+      await page.getByPlaceholder('Search wiki').click();
+      // workaround: HTMX listens on keyup events, playwright's fill only triggers the input event
+      // so we manually "type" the last letter
+      await page.getByPlaceholder('Search wiki').dispatchEvent('keyup');
+      // timeout is necessary because HTMX search could be slow
+      await expect(page.locator('#wiki-search a[href]')).toBeInViewport({ratio: 1});
+    });
+  }
+}
 
 test(`Search results show titles (and not file names)`, async ({page}, workerInfo) => {
   test.skip(workerInfo.project.name === 'Mobile Safari', 'Fails as always, see https://codeberg.org/forgejo/forgejo/pulls/5326#issuecomment-2313275');
diff --git a/tests/gitea-repositories-meta/user2/repo1.wiki.git/objects/53/0ab3e043bf2295fd1cec3129bf203a4349597a b/tests/gitea-repositories-meta/user2/repo1.wiki.git/objects/53/0ab3e043bf2295fd1cec3129bf203a4349597a
new file mode 100644
index 0000000000..eeae5d2b64
Binary files /dev/null and b/tests/gitea-repositories-meta/user2/repo1.wiki.git/objects/53/0ab3e043bf2295fd1cec3129bf203a4349597a differ
diff --git a/tests/gitea-repositories-meta/user2/repo1.wiki.git/objects/bf/29486462016efad8872371078932d8c2cb5253 b/tests/gitea-repositories-meta/user2/repo1.wiki.git/objects/bf/29486462016efad8872371078932d8c2cb5253
new file mode 100644
index 0000000000..ab5b5954cb
Binary files /dev/null and b/tests/gitea-repositories-meta/user2/repo1.wiki.git/objects/bf/29486462016efad8872371078932d8c2cb5253 differ
diff --git a/tests/gitea-repositories-meta/user2/repo1.wiki.git/objects/c0/b5b381e2df9f66d11e8c95fe7467b8fb7f3e4e b/tests/gitea-repositories-meta/user2/repo1.wiki.git/objects/c0/b5b381e2df9f66d11e8c95fe7467b8fb7f3e4e
new file mode 100644
index 0000000000..0474927fd2
Binary files /dev/null and b/tests/gitea-repositories-meta/user2/repo1.wiki.git/objects/c0/b5b381e2df9f66d11e8c95fe7467b8fb7f3e4e differ
diff --git a/tests/gitea-repositories-meta/user2/repo1.wiki.git/objects/d4/9ac742d44063dcf69d4e0afe725813b777dd89 b/tests/gitea-repositories-meta/user2/repo1.wiki.git/objects/d4/9ac742d44063dcf69d4e0afe725813b777dd89
new file mode 100644
index 0000000000..9dc276f37d
--- /dev/null
+++ b/tests/gitea-repositories-meta/user2/repo1.wiki.git/objects/d4/9ac742d44063dcf69d4e0afe725813b777dd89
@@ -0,0 +1 @@
+x���n�@������*���Gj��mJ��C1���~R0�ӧi}�*�U����*gw>�H�˺��5�6}���3�)Sh��0�9�Tƨ�;2i2��-�^j��L�4wS�۪p�mSTȭ��\9V��1S�p"������|���Ǔ���.Z>�법us�u�G�63����)"9��G�޶.��.��O��� �#X�J$����	�?o<1�_�)n�/�~��6���cS��l<�X�iҖb3{@��B,g���	�����K|��E�[�0\���aW�ݢR�|��i{���xd������9<��ҏ�g>���KOv�"D�J�sE��؜z���[�_s!2ϡ�v%�e��o(��
\ No newline at end of file
diff --git a/tests/gitea-repositories-meta/user2/repo1.wiki.git/refs/heads/master b/tests/gitea-repositories-meta/user2/repo1.wiki.git/refs/heads/master
index 38984b12b7..c804802cbf 100644
--- a/tests/gitea-repositories-meta/user2/repo1.wiki.git/refs/heads/master
+++ b/tests/gitea-repositories-meta/user2/repo1.wiki.git/refs/heads/master
@@ -1 +1 @@
-0dca5bd9b5d7ef937710e056f575e86c0184ba85
+d49ac742d44063dcf69d4e0afe725813b777dd89
diff --git a/tests/integration/api_wiki_test.go b/tests/integration/api_wiki_test.go
index b930791969..e086fa26af 100644
--- a/tests/integration/api_wiki_test.go
+++ b/tests/integration/api_wiki_test.go
@@ -133,8 +133,31 @@ func TestAPIListWikiPages(t *testing.T) {
 			},
 		},
 		{
-			Title:   "Page With Image",
+			Title:   "Long Page",
 			HTMLURL: meta[1].HTMLURL,
+			SubURL:  "Long-Page",
+			LastCommit: &api.WikiCommit{
+				ID: "d49ac742d44063dcf69d4e0afe725813b777dd89",
+				Author: &api.CommitUser{
+					Identity: api.Identity{
+						Name:  "Oto Šťáva",
+						Email: "oto.stava@gmail.com",
+					},
+					Date: "2024-11-23T11:16:51Z",
+				},
+				Committer: &api.CommitUser{
+					Identity: api.Identity{
+						Name:  "Oto Šťáva",
+						Email: "oto.stava@gmail.com",
+					},
+					Date: "2024-11-23T11:16:51Z",
+				},
+				Message: "add long page\n",
+			},
+		},
+		{
+			Title:   "Page With Image",
+			HTMLURL: meta[2].HTMLURL,
 			SubURL:  "Page-With-Image",
 			LastCommit: &api.WikiCommit{
 				ID: "0cf15c3f66ec8384480ed9c3cf87c9e97fbb0ec3",
@@ -157,7 +180,7 @@ func TestAPIListWikiPages(t *testing.T) {
 		},
 		{
 			Title:   "Page With Spaced Name",
-			HTMLURL: meta[2].HTMLURL,
+			HTMLURL: meta[3].HTMLURL,
 			SubURL:  "Page-With-Spaced-Name",
 			LastCommit: &api.WikiCommit{
 				ID: "c10d10b7e655b3dab1f53176db57c8219a5488d6",
@@ -180,7 +203,7 @@ func TestAPIListWikiPages(t *testing.T) {
 		},
 		{
 			Title:   "Unescaped File",
-			HTMLURL: meta[3].HTMLURL,
+			HTMLURL: meta[4].HTMLURL,
 			SubURL:  "Unescaped-File",
 			LastCommit: &api.WikiCommit{
 				ID: "0dca5bd9b5d7ef937710e056f575e86c0184ba85",
diff --git a/web_src/css/modules/container.css b/web_src/css/modules/container.css
index f394d6c06d..95c71b207f 100644
--- a/web_src/css/modules/container.css
+++ b/web_src/css/modules/container.css
@@ -3,12 +3,14 @@
 
 .ui.container {
   display: block;
-  max-width: 100%;
+  --container-width: 100%;
+  max-width: var(--container-width);
 }
 
 @media (max-width: 767.98px) {
   .ui.ui.ui.container:not(.fluid) {
-    width: auto;
+    --container-width: auto;
+    width: var(--container-width);
     margin-left: 1em;
     margin-right: 1em;
   }
@@ -16,7 +18,8 @@
 
 @media (min-width: 768px) and (max-width: 991.98px) {
   .ui.ui.ui.container:not(.fluid) {
-    width: 723px;
+    --container-width: 723px;
+    width: var(--container-width);
     margin-left: auto;
     margin-right: auto;
   }
@@ -24,7 +27,8 @@
 
 @media (min-width: 992px) and (max-width: 1199.98px) {
   .ui.ui.ui.container:not(.fluid) {
-    width: 933px;
+    --container-width: 933px;
+    width: var(--container-width);
     margin-left: auto;
     margin-right: auto;
   }
@@ -32,14 +36,16 @@
 
 @media (min-width: 1200px) {
   .ui.ui.ui.container:not(.fluid) {
-    width: 1127px;
+    --container-width: 1127px;
+    width: var(--container-width);
     margin-left: auto;
     margin-right: auto;
   }
 }
 
 .ui.fluid.container {
-  width: 100%;
+  --container-width: 100%;
+  width: var(--container-width);
 }
 
 .ui[class*="center aligned"].container {
@@ -48,7 +54,8 @@
 
 /* overwrite width of containers inside the main page content div (div with class "page-content") */
 .page-content .ui.ui.ui.container:not(.fluid) {
-  width: 1280px;
+  --container-width: 1280px;
+  width: var(--container-width);
   max-width: calc(100% - calc(2 * var(--page-margin-x)));
   margin-left: auto;
   margin-right: auto;