r/reactjs • • Sep 14 '26

How to apply Element-level styles on only a single component.

In my app I read back some markdown, there is some parsing done on it.

I am left with as the result a lot of <h1>, <h2>, <em>. In my app, due to using tailwind and other factors I don't have the default web browser styling on nor do I want to.

I want to implement that web browser styling back for just the html that came from the markdown, so I tried creating a css file that goes like

h1{
font-size: 48em
}

You get the idea, but now it applies to my entire app. Since the html comes from persist markdown it wouldn't be very reasonably to try to persistent styles on it (If you have any idea on how markdown works), and to try to add classnames to specific elements when they come in seems like unnecessary trouble.

How would you go around styling HTML based off just it's element in a small portion of the app?

Best,
Brotherman

0 Upvotes

7 comments sorted by

11

u/Prestigious_Dare7734 Sep 14 '26 edited Sep 14 '26

.markdown H1:not([class])

Wrap all your markdown in a parent .markdown class, then the not pseudo selector will select all the tags (H1 in this case) that do not have any class, so plain html tags.

1

u/BrotherManAndrew Sep 14 '26

Thank you so much bro <3