Skip to content

How to Style? Best practices and recommendations? #20170

Answered by dkozar
dggsax asked this question in General
Discussion options

You must be logged in to vote

It's important to understand the difference between style, styles and className props.

CSS in JS (mergeStyles, mergeStyleSets) is used with className prop, whereas style and styles are inline styles, applied directly to DOM element's style property.

CSS in JS is a true CSS, meaning it injects CSS style declarations to document's <head>.

With CSS in JS you could use most of the CSS features like cascading etc.

Quick demo

To understand what CSS in JS does:

/* copy-paste to your browser console and hit Enter */ 
var style = document.createElement('style'); 
style.innerHTML = "div {border: 5px solid black; background-color: blue;}"; 
document.head.appendChild(style); 

If you go (for example) to

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@dggsax
Comment options

@dkozar
Comment options

@dkozar
Comment options

@dkozar
Comment options

Answer selected by dggsax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants