by Audrey M. Roy Greenfeld | Fri, May 9, 2025
How to retrieve the CSS classes for a FastHTML FastTag instance.
from fasthtml.common import *
Here's a typical div with several Tailwind CSS classes:
d = Div(cls="container mx-auto p-4 bg-white dark:bg-gray-800")
d
The FT variable d
has these attrs
:
d.attrs
To get the CSS classes, you get the class
attribute of d
:
d.attrs['class']
Then you can split the space-separated string into a list, if you like:
css_classes = d.attrs['class'].split() css_classes