Skip to main content

Command Palette

Search for a command to run...

Using the HTML style Tag to Style a React Component

Styling React components with raw CSS and no extra files

Updated
3 min readView as Markdown
Using the HTML style Tag to Style a React Component

There are many ways to style a component in React, but some are more popular than others. Let's say you want to use raw CSS. Also, for the sake of simplicity, you do not want to externalize your style definition into another file.

Did you know this is actually possible in vanilla React? And how can you achieve this goal? Thanks to the HTML style element!

The <style>HTML element contains style information for a document, or part of a document. It contains CSS, which is applied to the contents of the document containing the <style> element. —