Skip to content

Streamlit 테마 설정 및 UI 디자인 가이드: config.toml로 색상·다크모드·폰트 꾸미기

게시일

업데이트

핵심 요약: 프로젝트 루트 디렉터리(app.py가 있는 위치)에 .streamlit/config.toml 파일을 만들고 [theme] 섹션을 추가한 뒤 streamlit run app.py를 다시 실행하면 앱 전체 UI 디자인이 즉시 바뀝니다.

# .streamlit/config.toml
[theme]
base = "light"
primaryColor = "#2563EB"
backgroundColor = "#FFFFFF"
secondaryBackgroundColor = "#F3F4F6"
textColor = "#111827"
font = "sans serif"

CSS를 직접 작성하지 않아도 이 설정 파일 하나로 버튼, 슬라이더, 사이드바, 입력창, 폰트까지 일관된 톤으로 통일할 수 있습니다. 이 가이드에서는 핵심 옵션 표, 바로 복사해 쓸 수 있는 4가지 테마 프리셋, 사이드바 전용 테마([theme.sidebar]), 최신 커스텀 폰트 설정([[theme.fontFaces]] 및 Google Fonts), 최신 CSS 선택자, 그리고 config.toml이 반영되지 않을 때의 트러블슈팅까지 실무 기준으로 정리합니다.

인기 글

.streamlit/config.toml 파일 위치와 적용 범위

Streamlit은 아래 두 위치에서 설정 파일을 읽으며, 프로젝트 설정이 전역 설정보다 우선 적용됩니다.

your-streamlit-app/
├── .streamlit/
│   └── config.toml      # 프로젝트별 테마 설정 (권장, Git에 함께 커밋)
├── static/              # 선택 사항: 로컬 커스텀 폰트나 정적 리소스
└── app.py
  • 프로젝트 단위: 프로젝트_루트/.streamlit/config.toml — 해당 폴더에서 streamlit run app.py를 실행할 때 자동 적용되며, Streamlit Community Cloud 배포 시에도 그대로 반영됩니다.
  • 사용자 전역: ~/.streamlit/config.toml — 로컬에서 실행하는 모든 Streamlit 앱의 기본 테마로 적용됩니다.
  • CLI 임시 덮어쓰기: 현재 적용 중인 설정을 확인하려면 streamlit config show를 실행하고, 실행 시점에만 테마를 임시로 바꾸려면 streamlit run에 --theme.* 플래그를 직접 전달하세요.
streamlit run app.py --theme.base="dark" --theme.primaryColor="#38BDF8"

[theme] 핵심 옵션 정리

모든 색상 값은 따옴표로 감싼 HEX 코드("#RRGGBB")로 입력합니다. 생략한 항목은 base ("light" 또는 "dark")의 기본값을 자동으로 상속합니다.

옵션사용 가능한 값적용되는 UI 요소
base"light" 또는 "dark"명시하지 않은 나머지 색상의 기준 팔레트
primaryColorHEX 색상 (예: "#2563EB")주요 버튼, 활성 슬라이더, 체크박스, 선택된 탭, 포커스 강조색
backgroundColorHEX 색상 (예: "#FFFFFF")메인 페이지 전체 배경색
secondaryBackgroundColorHEX 색상 (예: "#F3F4F6")사이드바 배경, 입력 필드, 코드 블록, expander 영역 배경
textColorHEX 색상 (예: "#111827")본문 텍스트, 제목, 위젯 라벨 글자색
font"sans serif", "serif", "monospace" 또는 커스텀 폰트 (1.44+)앱 전반의 기본 글꼴

바로 복붙해 쓰는 Streamlit UI 디자인 프리셋 4종

원하는 스타일을 .streamlit/config.toml에 복사해 붙여 넣고 서버를 재시작하면 됩니다.

1. Clean Light (깔끔한 모던 SaaS 스타일)

가독성이 높은 무채색 바탕에 선명한 블루 포인트를 조합해 데이터 대시보드나 사내 툴에 가장 무난합니다.

[theme]
base = "light"
primaryColor = "#2563EB"
backgroundColor = "#FFFFFF"
secondaryBackgroundColor = "#F8FAFC"
textColor = "#0F172A"
font = "sans serif"

2. Midnight Dark (개발자·모니터링용 다크 모드)

눈의 피로를 줄이는 딥 슬레이트 배경에 밝은 스카이블루 강조색을 배치해 차트와 지표가 또렷하게 보입니다.

[theme]
base = "dark"
primaryColor = "#38BDF8"
backgroundColor = "#0F172A"
secondaryBackgroundColor = "#1E293B"
textColor = "#F1F5F9"
font = "sans serif"

3. Corporate Blue (비즈니스·리포트 스타일)

금융, BI, 경영진 보고용 대시보드에 어울리는 안정감 있는 네이비·블루 톤입니다.

[theme]
base = "light"
primaryColor = "#1D4ED8"
backgroundColor = "#F8FAFC"
secondaryBackgroundColor = "#E2E8F0"
textColor = "#1E293B"
font = "sans serif"

4. Warm Minimal (에디토리얼·리서치 스타일)

부드러운 미색 배경과 세리프 글꼴을 조합해 분석 리포트, 인터랙티브 아티클, 프로토타입 데모에 잘 어울립니다.

[theme]
base = "light"
primaryColor = "#B45309"
backgroundColor = "#FAF7F2"
secondaryBackgroundColor = "#F0EAE0"
textColor = "#292524"
font = "serif"

사이드바만 별도로 디자인하기 ([theme.sidebar])

Streamlit 1.44 이상에서는 [theme.sidebar] 섹션을 사용해 메인 영역은 밝게 두고 사이드바만 어두운 네비게이션 바처럼 꾸밀 수 있습니다.

[theme]
base = "light"
primaryColor = "#2563EB"
backgroundColor = "#FFFFFF"
secondaryBackgroundColor = "#F1F5F9"
textColor = "#0F172A"
 
[theme.sidebar]
backgroundColor = "#0F172A"
secondaryBackgroundColor = "#1E293B"
textColor = "#F8FAFC"
primaryColor = "#38BDF8"

[theme.sidebar]에서 생략한 속성은 상위 [theme] 설정을 그대로 따릅니다.

다크 모드와 라이트 모드 전환 동작

앱 실행 중 사용자는 우측 상단 메뉴(⋮ → Settings → Choose app theme)에서 Light, Dark, Use system setting, Custom Theme 중 원하는 모드를 직접 선택할 수 있습니다.

실무에서 자주 놓치는 포인트 두 가지입니다.

  • .streamlit/config.toml에 [theme]이 정의되어 있으면 처음 접속하는 사용자에게는 자동으로 Custom Theme이 기본 적용됩니다.
  • 다크 테마를 직접 커스텀할 때는 반드시 base = "dark"를 함께 지정하세요. 그래야 경계선, 툴팁, 모달, 기본 차트 축 색상까지 어두운 배경에 맞게 자연스럽게 어우러집니다.

Streamlit 폰트 커스텀 (기본 폰트 · 로컬 폰트 · Google Fonts)

기본 내장 폰트 (모든 버전)

모든 Streamlit 버전에서 font 옵션에 바로 넣을 수 있는 기본 키워드는 세 가지입니다.

[theme]
font = "sans serif" # 또는 "serif", "monospace"

font = "Helvetica Neue"처럼 등록되지 않은 폰트 이름만 단독으로 적으면 동작하지 않으며, 커스텀 폰트를 쓰려면 아래 방식을 사용해야 합니다.

로컬 커스텀 폰트 ([[theme.fontFaces]], Streamlit 1.44+)

Pretendard나 Noto Sans KR 같은 웹폰트 파일(.woff2 등)을 프로젝트 루트의 static/ 폴더에 넣고 정적 서빙을 켠 뒤 [[theme.fontFaces]]로 등록합니다.

[server]
enableStaticServing = true
 
[theme]
base = "light"
font = "PretendardCustom"
headingFont = "PretendardCustom"
 
[[theme.fontFaces]]
family = "PretendardCustom"
url = "app/static/Pretendard-Regular.woff2"
weight = 400
style = "normal"
 
[[theme.fontFaces]]
family = "PretendardCustom"
url = "app/static/Pretendard-Bold.woff2"
weight = 700
style = "normal"

Google Fonts 인라인 지정 (Streamlit 1.50+)

Streamlit 1.50 이상에서는 폰트명:CSS2_URL 형식으로 Google Fonts를 config.toml에서 바로 불러올 수 있습니다. 공백이 포함된 폰트 이름은 큰따옴표 안에 작은따옴표로 한 번 더 감쌉니다.

[theme]
font = "'Noto Sans KR':https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;600;700&display=swap"
codeFont = "'JetBrains Mono':https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600&display=swap"

커스텀 CSS와 배경 이미지 적용 (최신 선택자)

배경 이미지, 그라데이션, 카드 여백처럼 config.toml만으로 해결되지 않는 세부 UI 디자인은 st.markdown(..., unsafe_allow_html=True)(또는 Streamlit 1.33+의 st.html(...))로 CSS를 주입합니다.

구버전(Streamlit 0.x)의 오래된 클래스 선택자는 이미 제거되어 동작하지 않습니다. 대신 최신 Streamlit의 data-testid 선택자를 사용하세요.

import streamlit as st
 
st.markdown(
    """
    <style>
    [data-testid="stAppViewContainer"] {
        background: linear-gradient(180deg, #F8FAFC 0%, #EFF6FF 100%);
    }
 
    [data-testid="stSidebar"] {
        border-right: 1px solid #E2E8F0;
    }
    </style>
    """,
    unsafe_allow_html=True,
)

메인 화면에 배경 이미지를 넣고 싶다면 [data-testid="stAppViewContainer"]에 background-image와 background-size: cover를 지정합니다.

import streamlit as st
 
st.markdown(
    """
    <style>
    [data-testid="stAppViewContainer"] {
        background-image: url("https://your-cdn.example.com/bg.jpg");
        background-size: cover;
        background-position: center;
    }
    </style>
    """,
    unsafe_allow_html=True,
)

유지보수 주의: Streamlit 내부 DOM 구조와 data-testid 속성은 버전 업그레이드 시 예고 없이 변경될 수 있습니다. 색상·폰트·사이드바 톤은 가급적 .streamlit/config.toml로 관리하고, CSS 주입은 최소한의 보조 디자인에만 사용하는 것이 안전합니다.

트러블슈팅: config.toml 테마가 적용되지 않을 때 체크리스트

.streamlit/config.toml을 수정했는데 화면이 그대로라면 아래 4가지를 순서대로 확인하세요.

  1. 서버를 재시작하지 않음: .streamlit/config.toml을 새로 만들거나 폰트/서버 옵션을 바꾼 뒤에는 실행 중인 프로세스를 종료(Ctrl+C)하고 streamlit run app.py를 다시 실행해야 합니다.
  2. 작업 디렉터리 불일치: Streamlit은 streamlit run을 실행한 현재 작업 디렉터리 기준으로 .streamlit/config.toml을 찾습니다. 실제로 어떤 설정이 로드되었는지 아래 명령으로 확인하세요.
    streamlit config show
  3. 브라우저 Settings 캐시 덮어쓰기: 이전에 브라우저 우측 상단 ⋮ → Settings에서 Light 또는 Dark를 직접 선택했다면, 브라우저 localStorage가 config.toml보다 우선 적용됩니다. Settings에서 Custom Theme으로 되돌리거나 시크릿 창에서 확인하세요.
  4. TOML 문법 오류: HEX 색상은 반드시 따옴표로 감싸야 합니다("#2563EB"). 따옴표 없이 #2563EB라고 쓰면 # 뒤가 전부 TOML 주석으로 처리됩니다.

데이터 시각화 앱 팁: 앱 테마를 깔끔하게 다듬은 뒤 Streamlit 안에서 Tableau처럼 드래그 앤 드롭으로 DataFrame을 탐색할 수 있는 인터페이스가 필요하다면 PyGWalker (opens in a new tab)를 함께 연동해 볼 수 있습니다(Streamlit에서 PyGWalker 사용하기).

FAQ

Streamlit 테마와 UI 색상은 어디서 설정하나요?

프로젝트 루트에 .streamlit/config.toml 파일을 만들고 [theme] 섹션에 base, primaryColor, backgroundColor, secondaryBackgroundColor, textColor, font 옵션을 지정한 뒤 streamlit run app.py를 재시작하면 됩니다.

config.toml을 수정했는데 Streamlit 테마가 바뀌지 않는 이유는 무엇인가요?

대표적인 원인 4가지는 (1) 서버를 재시작하지 않은 경우, (2) streamlit run을 실행한 디렉터리와 .streamlit/config.toml 위치가 다른 경우(streamlit config show로 확인), (3) 브라우저 Settings 메뉴에서 Light/Dark를 수동 선택해 캐시가 덮어쓰는 경우, (4) HEX 색상에 따옴표를 빼먹어 TOML 주석으로 처리된 경우입니다.

Streamlit에서 한글 폰트나 Google Fonts를 적용할 수 있나요?

네. Streamlit 1.44 이상에서는 static/ 폴더에 .woff2 폰트 파일을 넣고 enableStaticServing = true와 [[theme.fontFaces]]로 로컬 한글 폰트(예: Pretendard)를 등록할 수 있습니다. Streamlit 1.50 이상에서는 config.toml에 Google Fonts CSS2 URL을 직접 지정하는 방식도 지원합니다.

Streamlit 사이드바 색상만 메인 화면과 다르게 바꿀 수 있나요?

Streamlit 1.44 이상에서 .streamlit/config.toml 안에 [theme.sidebar] 섹션을 추가하고 backgroundColor, secondaryBackgroundColor, textColor 등을 별도로 지정하면 사이드바만 독립적으로 스타일링할 수 있습니다.

Streamlit에 커스텀 CSS나 배경 이미지를 넣을 때 어떤 선택자를 쓰나요?

구버전 Streamlit 0.x의 레거시 클래스 선택자는 제거되어 동작하지 않습니다. st.markdown(..., unsafe_allow_html=True) 또는 st.html(...)에서 [data-testid="stAppViewContainer"]와 [data-testid="stSidebar"] 같은 최신 선택자를 사용하되, 버전 업데이트에 대비해 기본 색상은 config.toml로 관리하는 것이 안전합니다.

관련 가이드