Skip to content

Instantly share code, notes, and snippets.

@wmayner
Last active January 6, 2025 14:04
Show Gist options
  • Save wmayner/9b099a0e4a5f8e94f0c6ab2f570187a5 to your computer and use it in GitHub Desktop.
Save wmayner/9b099a0e4a5f8e94f0c6ab2f570187a5 to your computer and use it in GitHub Desktop.
Display a color swatch from hex color strings with IPython in a Jupyter Notebook
from IPython.display import Markdown, display
colors = ['#018700', '#00acc6', '#e6a500']
display(Markdown('<br>'.join(
f'<span style="font-family: monospace">{color} <span style="color: {color}">████████</span></span>'
for color in colors
)))
@nickserv
Copy link

Note that Google Collaboratory sanitizes HTML in Markdown. I'd recommend using Html instead of Markdown, which I think makes the intent more clear anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment