--- title: Streamlit st.html 注入全局 CSS 的坑:内容含 '<' 会被 DOMPurify 整段丢弃 type: experience permalink: main/projects/8e229c96-a83b-4a02-ac40-10a0a9da444e/streamlit-st.html-注入全局-css-的坑内容含-会被-dompurify-整段丢弃 stable_id: 30702060-b113-4e9e-b1f0-2553e8b35046 scope: project memory_type: experience project_id: 8e229c96-a83b-4a02-ac40-10a0a9da444e usage_profile_id: 7aee455b-24cc-4008-bdaf-443721e6f939 status: active revision: 1 request_id: marketgrid-exp-sthtml-dompurify-20260917 created_at: '2026-09-17T01:51:39.047480+00:00' updated_at: '2026-09-17T01:51:39.047480+00:00' tags: - streamlit - css - st.html - dompurify - ui --- 问题:在 ui/layout.py 的 COMPACT_CSS 中加入内联 SVG data URL(含 ``)后,界面所有紧凑布局、隐藏 Enter 提示等全局样式同时失效;DOM 中 stEvent 容器的元素为空。 原因:Streamlit 1.64 的 `st.html` 对内容做 DOMPurify 清洗,纯 `