Jump to content
Wikipedia The Free Encyclopedia

CSS-in-JS

From Wikipedia, the free encyclopedia
This article provides insufficient context for those unfamiliar with the subject. Please help improve the article by providing more context for the reader. (July 2019) (Learn how and when to remove this message)

CSS-in-JS is a styling technique by which JavaScript is used to style components. When this JavaScript is parsed, CSS is generated (usually as a <style> element) and attached into the DOM. It enables the abstraction of CSS to the component level itself, using JavaScript to describe styles in a declarative and maintainable way. There are multiple implementations of this concept in the form of libraries such as

These libraries allow the creation of styled components using tagged template literals. For example, using styled components in a React project would look like the following:

importstyledfrom'styled-components';
// Create a component that renders a <p> element with blue text
constBlueText=styled.p`
 color: blue;
`;
<BlueText>Mybluetext</BlueText>

Some outcomes that may be achieved through CSS-in-JS can not be obtained using traditional CSS techniques. It is possible to make the styles dynamic in line with just a few conditional statements. Programmers may also write more modular code, with CSS being encapsulated in the same block as the programmer's JavaScript, scoping it to that module only.

Industry use

[edit ]

CSS-in-JS is used by Reddit, Patreon, Target, Atlassian, Vogue, GitHub and Coinbase.[4]

References

[edit ]
  1. ^ "Emotion - Introduction". emotion.sh. Retrieved 2019年07月03日.
  2. ^ styled-components. "styled-components". styled-components. Retrieved 2019年07月03日.
  3. ^ "JSS". cssinjs.org. Retrieved 2019年07月03日.
  4. ^ "A Detailed Explanation of CSS-in-JS". Alibaba Cloud Community. Retrieved 2023年07月05日.
Code analysis
Subsets,* supersets
Transpilers
Concepts
Debuggers
Documentation generators
Editors (comparison)
Engines
Frameworks
Related technologies
Package managers
Module bundlers
Server-side
Unit testing frameworks (list)
People

AltStyle によって変換されたページ (->オリジナル) /