diff --git a/sphinx/builders/html/__init__.py b/sphinx/builders/html/__init__.py
index 1dbde6e371e..6a069c3cad1 100644
--- a/sphinx/builders/html/__init__.py
+++ b/sphinx/builders/html/__init__.py
@@ -1036,7 +1036,7 @@ def hasdoc(name: str) -> bool:
# sort JS/CSS before rendering HTML
ctx['script_files'].sort(key=lambda js: js.priority)
- ctx['css_files'].sort(key=lambda js: js.priority)
+ ctx['css_files'].sort(key=lambda css: css.priority)
try:
output = self.templates.render(templatename, ctx)