diff --git a/docs/src/markdown/about/changelog.md b/docs/src/markdown/about/changelog.md
index 78afda9..3afed4f 100644
--- a/docs/src/markdown/about/changelog.md
+++ b/docs/src/markdown/about/changelog.md
@@ -2,6 +2,7 @@
 
 ## 1.7.2
 
+- **FIX**: Fix HTML detection `type` selector.
 - **FIX**: Provide a way for Beautiful Soup to parse selectors in a quirks mode to mimic some of the quirks of the old
   select method prior to Soup Sieve, but with warnings. This is to help old scripts to not break during the transitional
   period with newest Beautiful Soup. In the future, these quirks will raise an exception as Soup Sieve requires
diff --git a/soupsieve/css_match.py b/soupsieve/css_match.py
index 6a9b485..d1a5c35 100644
--- a/soupsieve/css_match.py
+++ b/soupsieve/css_match.py
@@ -547,7 +547,7 @@ class CSSMatch(Document, object):
         if attributes:
             for a in attributes:
                 value = self.match_attribute_name(el, a.attribute, a.prefix)
-                pattern = a.xml_type_pattern if not self.html_namespace and a.xml_type_pattern else a.pattern
+                pattern = a.xml_type_pattern if self.is_xml and a.xml_type_pattern else a.pattern
                 if isinstance(value, list):
                     value = ' '.join(value)
                 if value is None:

HTML detection for `type` selector not working correctly
Fix issue noted here: https://github.com/MechanicalSoup/MechanicalSoup/pull/263.

We were checking against the html namespace for type case insensitivity instead of whether the document was XML or not.

diff --git a/tests/test_level2.py b/tests/test_level2.py
index b83b4cf..f8a5a6a 100644
--- a/tests/test_level2.py
+++ b/tests/test_level2.py
@@ -337,6 +337,20 @@ class TestLevel2(util.TestCase):
             flags=util.HTML5
         )
 
+        self.assert_selector(
+            markup,
+            '[type="test"]',
+            ["0", '2'],
+            flags=util.HTML
+        )
+
+        self.assert_selector(
+            markup,
+            '[type="test"]',
+            ["0", '2'],
+            flags=util.PYHTML
+        )
+
         self.assert_selector(
             markup,
             '[type="test"]',
@@ -344,6 +358,35 @@ class TestLevel2(util.TestCase):
             flags=util.XML
         )
 
+        markup = """
+        <?xml version="1.0" encoding="UTF-8"?>
+        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
+            "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+        <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
+        <head>
+        </head>
+        <body>
+        <div id="div">
+        <p type="TEST" id="0">Some text <span id="1"> in a paragraph</span>.</p>
+        <a type="test" id="2" href="http://google.com">Link</a>
+        <span id="3">Direct child</span>
+        <pre id="pre">
+        <span id="4">Child 1</span>
+        <span id="5">Child 2</span>
+        <span id="6">Child 3</span>
+        </pre>
+        </div>
+        </body>
+        </html>
+        """
+
+        self.assert_selector(
+            markup,
+            '[type="test"]',
+            ["0", '2'],
+            flags=util.XML
+        )
+
     def test_attribute_start_dash(self):
         """Test attribute whose dash separated value starts with the specified value."""
 
diff --git a/tests/util.py b/tests/util.py
index 0734a95..958873a 100644
--- a/tests/util.py
+++ b/tests/util.py
@@ -12,6 +12,7 @@ HTML5 = 1
 HTML = 2
 XHTML = 4
 XML = 8
+PYHTML = 10
 
 
 def skip_quirks(func):
@@ -66,7 +67,9 @@ class TestCase(unittest.TestCase):
         """Assert selector."""
 
         mode = flags & 0x0F
-        if mode == HTML:
+        if mode == PYHTML:
+            bs_mode = 'html.parser'
+        elif mode == HTML:
             bs_mode = 'lxml'
         elif mode in (HTML5, 0):
             bs_mode = 'html5lib'

pip install -e .
parse_log_pytest
requirements.txt
pytest pytest-cov coverage
apt-get update apt-get install -y gcc
3.6
requirements/project.txt requirements/tests.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs==22.2.0
beautifulsoup4==4.12.3
certifi==2021.5.30
coverage==6.2
html5lib==1.1
importlib-metadata==4.8.3
iniconfig==1.1.1
lxml==5.3.1
packaging==21.3
pluggy==1.0.0
py==1.11.0
pyparsing==3.1.4
pytest==7.0.1
pytest-cov==4.0.0
six==1.17.0
-e git+https://github.com/facelessuser/soupsieve.git@834413f6cda3f6ba0c520e82a4ddf265fba0a226#egg=soupsieve
tomli==1.2.3
typing_extensions==4.1.1
webencodings==0.5.1
zipp==3.6.0

name: soupsieve
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - attrs==22.2.0
      - beautifulsoup4==4.12.3
      - coverage==6.2
      - html5lib==1.1
      - importlib-metadata==4.8.3
      - iniconfig==1.1.1
      - lxml==5.3.1
      - packaging==21.3
      - pluggy==1.0.0
      - py==1.11.0
      - pyparsing==3.1.4
      - pytest==7.0.1
      - pytest-cov==4.0.0
      - six==1.17.0
      - tomli==1.2.3
      - typing-extensions==4.1.1
      - webencodings==0.5.1
      - zipp==3.6.0
prefix: /opt/conda/envs/soupsieve

tests/test_level2.py::TestLevel2::test_attribute_type tests/test_level2.py::TestLevel2Quirks::test_attribute_type
tests/test_level2.py::TestLevel2::test_at_rule tests/test_level2.py::TestLevel2::test_attribute tests/test_level2.py::TestLevel2::test_attribute_contains_space tests/test_level2.py::TestLevel2::test_attribute_equal tests/test_level2.py::TestLevel2::test_attribute_quirks tests/test_level2.py::TestLevel2::test_attribute_start_dash tests/test_level2.py::TestLevel2::test_comments tests/test_level2.py::TestLevel2::test_direct_child tests/test_level2.py::TestLevel2::test_direct_sibling tests/test_level2.py::TestLevel2::test_first_child tests/test_level2.py::TestLevel2::test_focus tests/test_level2.py::TestLevel2::test_hover tests/test_level2.py::TestLevel2::test_lang tests/test_level2.py::TestLevel2::test_leading_combinator_quirks tests/test_level2.py::TestLevel2::test_multi_attribute tests/test_level2.py::TestLevel2::test_pseudo_element tests/test_level2.py::TestLevel2::test_wild_tag tests/test_level2.py::TestLevel2Quirks::test_at_rule tests/test_level2.py::TestLevel2Quirks::test_attribute tests/test_level2.py::TestLevel2Quirks::test_attribute_contains_space tests/test_level2.py::TestLevel2Quirks::test_attribute_equal tests/test_level2.py::TestLevel2Quirks::test_attribute_quirks tests/test_level2.py::TestLevel2Quirks::test_attribute_start_dash tests/test_level2.py::TestLevel2Quirks::test_comments tests/test_level2.py::TestLevel2Quirks::test_direct_child tests/test_level2.py::TestLevel2Quirks::test_direct_sibling tests/test_level2.py::TestLevel2Quirks::test_first_child tests/test_level2.py::TestLevel2Quirks::test_focus tests/test_level2.py::TestLevel2Quirks::test_hover tests/test_level2.py::TestLevel2Quirks::test_lang tests/test_level2.py::TestLevel2Quirks::test_leading_combinator_quirks tests/test_level2.py::TestLevel2Quirks::test_multi_attribute tests/test_level2.py::TestLevel2Quirks::test_pseudo_element tests/test_level2.py::TestLevel2Quirks::test_wild_tag
soupsieve/css_match.py docs/src/markdown/about/changelog.md
soupsieve/css_match.py docs/src/markdown/about/changelog.md