diff --git a/sphinx/builders/html/__init__.py b/sphinx/builders/html/__init__.py
index d85539bf648..cf76d432b02 100644
--- a/sphinx/builders/html/__init__.py
+++ b/sphinx/builders/html/__init__.py
@@ -1052,7 +1052,7 @@ def css_tag(css: _CascadingStyleSheet) -> str:
if value is not None]
uri = pathto(os.fspath(css.filename), resource=True)
# the EPUB format does not allow the use of query components
- if self.name != 'epub':
+ if not self.name.startswith('epub'):
if checksum := _file_checksum(outdir, css.filename):
uri += f'?v={checksum}'
return f''
@@ -1082,7 +1082,7 @@ def js_tag(js: _JavaScript | str) -> str:
# https://github.com/sphinx-doc/sphinx/issues/11658
pass
# the EPUB format does not allow the use of query components
- elif self.name != 'epub':
+ elif not self.name.startswith('epub'):
if checksum := _file_checksum(outdir, js.filename):
uri += f'?v={checksum}'
if attrs: