--- 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 project_id: 8e229c96-a83b-4a02-ac40-10a0a9da444e memory_type: experience status: active revision: 1 restored_from_commit: 6a6a895eafcca6052e81a14fca103a42635dd1c2 created_at: '2026-09-23T15:01:37.094752+00:00' updated_at: '2026-09-23T15:01:37.094807+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 清洗,纯 `