CSS-in-JS

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:

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

<BlueText>My blue text</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

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

References

  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.

Read other articles:

British actor Terence StampStamp in 2009BornTerence Henry Stamp (1938-07-22) 22 July 1938 (age 85)Stepney, London, EnglandAlma materWebber Douglas Academy of Dramatic ArtOccupationActorYears active1960–presentSpouse Elizabeth O'Rourke ​ ​(m. 2002; div. 2008)​RelativesChris Stamp (brother) Terence Henry Stamp (born 22 July 1938)[1][2] is an English actor. Known for his sophisticated villain roles, he was named by Emp…

Ohio railroad (1885–1926) Cincinnati, Lebanon and Northern RailwayCL&N (red)OverviewHeadquartersCincinnati, Ohio, U.S.[1]LocaleMiami Valley, OhioDates of operation1885–1926SuccessorPennsylvania RailroadTechnicalTrack gauge4 ft 8+1⁄2 in (1,435 mm) standard gaugePrevious gaugeoriginally 3 ft (914 mm) The Cincinnati, Lebanon and Northern Railway (CL&N) was a local passenger and freight-carrying railroad in the southwestern part of the U.S.…

Annual association football award event in France Award2018 Ballon d'Or2018 Ballon d'Or winner Luka ModrićDate3 December 2018 (2018-12-03)LocationParis, FranceCountryFrancePresented byFrance FootballHighlightsBallon d'Or Luka Modrić (1st award)Ballon d'Or Féminin Ada Hegerberg (1st award)Kopa Trophy Kylian Mbappé (1st award)Websitewww.francefootball.fr ← 2017 · Ballon d'Or · 2019 → The 2018 Ballon d'Or was the 63rd annual award ceremony recogn…

Cet article est une ébauche concernant un chanteur grec. Vous pouvez partager vos connaissances en l’améliorant (comment ?) selon les recommandations des projets correspondants. Yórgos AlkéosGiórgos Alkaios, 2010BiographieNaissance 24 décembre 1971 (52 ans)AthènesNom dans la langue maternelle Γιώργος ΑλκαίοςNom de naissance Γεώργιος ΒασιλείουNationalité grecqueActivité ChanteurPériode d'activité depuis 1989Père Giannis Vassiliou (en)Autres i…

土库曼斯坦总统土库曼斯坦国徽土库曼斯坦总统旗現任谢尔达尔·别尔德穆哈梅多夫自2022年3月19日官邸阿什哈巴德总统府(Oguzkhan Presidential Palace)機關所在地阿什哈巴德任命者直接选举任期7年,可连选连任首任萨帕尔穆拉特·尼亚佐夫设立1991年10月27日 土库曼斯坦土库曼斯坦政府与政治 国家政府 土库曼斯坦宪法 国旗 国徽 国歌 立法機關(英语:National Council of Turkmenistan) 土…

Military unit of the Papal States Guardia CorsaSoldier, officer and high officer of the Corsican Guard in 1656, after La Corse militaire, by Marquis Paul D'Ornano (1904)Active1603–1662Country Papal StatesTypeInfantryRole Honour guard urban militia Size600–700Garrison/HQRomeCommandersNotablecommandersMario ChigiMilitary unit The Corsican Guard (Italian and Corsican: Guardia Corsa) was a military unit of the Papal States composed exclusively of Corsican mercenaries on duty in Rome, having the …

Town and municipality in Puerto Rico Town and Municipality in Puerto Rico, United StatesCanóvanas Municipio de CanóvanasTown and MunicipalityAerial view of PR-3 passing through Canóvanas FlagCoat of armsNicknames: Pueblo Valeroso, Ciudad de los Indios, La Ciudad de las Carreras, El Pueblo del ChupacabrasAnthem: CanóvanaxMap of Puerto Rico highlighting Canóvanas MunicipalityCoordinates: 18°22′45″N 65°54′5″W / 18.37917°N 65.90139°W / 18.37917; -65.9013…

14th season in franchise history 2015 Houston Texans seasonOwnerBob McNairGeneral managerRick SmithHead coachBill O'BrienOffensive coordinatorGeorge GodseyDefensive coordinatorRomeo CrennelHome fieldNRG StadiumResultsRecord9–7Division place1st AFC SouthPlayoff finishLost Wild Card Playoffs(vs. Chiefs) 0–30Pro Bowlers 3 WR DeAndre Hopkins DE J. J. Watt LS Jon Weeks AP All-Pros 2 WR DeAndre Hopkins DE J. J. Watt Uniform ← 2014 Texans seasons 2016 → The 2015 Houston T…

Minister of DefenceRoyal Arms of Her Majesty's GovernmentLongest servingWinston Churchill10 May 1940 – 27 July 1945Ministry of Defence (1947–1964)StatusAbolishedMember ofCabinetReports toPrime MinisterPrecursorMinister for Co-ordination of DefenceFormation10 May 1940First holderWinston ChurchillFinal holderPeter ThorneycroftAbolished1 April 1964SuccessionSecretary of State for Defence The post of Minister of Defence was responsible for co-ordination of defence and security from its creation …

This article is about the general history of China from prehistoric times to the present. For the history of the Republic of China since 1912, see History of the Republic of China. For the history of the People's Republic of China since 1949, see History of the People's Republic of China. Approximate territorial extent of the various dynasties and states in Chinese history. Part of a series on theHistory of China Timeline Dynasties Historiography Prehistoric Paleolithic Neolithic (c. 8500&…

Revolutionary provisional government of New York State New York Provincial CongressTypeTypeUnicameral Provisional Revolutionary Government of Province of New YorkHistoryFoundedMay 22, 1775DisbandedApril 20, 1777Preceded byNew York General AssemblyCommittee of SixtySucceeded byNew York State LegislatureLeadershipPresidentPeter Van Brugh Livingston (first) Leonard Gansevoort (final) Chairmen of the Committee of SafetyNathaniel Woodhull (first)Leonard Gansevoort (final) President of the C…

  لمعانٍ أخرى، طالع كلارندون (توضيح). كلارندون   الإحداثيات 43°11′36″N 78°03′53″W / 43.193333333333°N 78.064722222222°W / 43.193333333333; -78.064722222222   [1] تقسيم إداري  البلد الولايات المتحدة[2]  التقسيم الأعلى مقاطعة أورلينز  خصائص جغرافية  المساحة 35.22 ميل مربع  ا…

المدن التوأمة في مصر هو الاتفاق بين مدينتين على التعاون في مختلف المجالات والأمور التي تعني التجمعات السكنية المدنية. وهي اتفاقية تعاون بين مدينتين، يوقع عليها عادة صاحب أعلى سلطة في كلا المدينتين. يقوم فريق من كلا المدينتين بإعداد بنود الاتفاقية. في الوطن العربي ترعى منظمة…

الهشاشمة تقسيم إداري البلد المغرب  الجهة مراكش آسفي الإقليم آسفي الدائرة كزولة الجماعة القروية لعمامرة المشيخة أولاد بوعيش السكان التعداد السكاني 156 نسمة (إحصاء 2004)   • عدد الأسر 23 معلومات أخرى التوقيت ت ع م±00:00 (توقيت قياسي)[1]،  وت ع م+01:00 (توقيت صيفي)[1]  تعدي…

Shruti HaasanInformasi latar belakangNama lahirShruti Rajalakshmi HaasanLahir28 Januari 1986 (umur 38)Chennai, Tamil Nadu, GenrePop, R&B, dance, rockPekerjaanAktris, Penyanyi, Supermodel, Komposer, PenariTahun aktif2000–present Shruti Rajalakshmi Haasan (lahir 28 Januari 1986) adalah seorang Aktris, Penyanyi, Supermodel, Komposer, dan Penari kewarganegaraan India yang merupakan salah satu Aktris di industri perfilman Bollywood. Diskografi Judul Tahun Film Komposer Catatan Potri Paadad…

Pour les articles homonymes, voir Bibliothèque bleue (homonymie). Un des succès de la Bibliothèque bleue : Huon de Bordeaux imprimé à Troyes par la veuve Oudot (Anne Hussard) vers 1720. La Bibliothèque bleue est une forme primitive de littérature de colportage apparue en France au début du XVIIe siècle. Principes La création et la diffusion de la bibliothèque bleue fut une activité particulièrement lucrative pour les imprimeurs. Vers la fin du XIXe siècle, le nombre d’i…

Forma neoasiria del signo É. É[1]​ (o E2) es la palabra o símbolo sumerio para casa o templo, escrito ideográficamente con el signo cuneiforme 𒂍 (Borger nº 324, codificado por Unicode con punto de código Unicode U+1208D). El término sumerio É.GAL (palacio, literalmente casa grande) designa al edificio principal de una ciudad. É.LUGAL (casa del rey) se utilizaba como sinónimo. En los textos de Lagash, el É.GAL también era el centro de administración de los ensi en las ciudad…

International airport serving Orange County and Santa Ana, California, United States For other uses, see Orange County Airport (disambiguation) and JWA (disambiguation). John Wayne AirportIATA: SNAICAO: KSNAFAA LID: SNASummaryAirport typePublicOwner/OperatorOrange CountyServesOrange County / Santa AnaLocation18601 Airport WaySanta Ana, California, U.S.Elevation AMSL56 ft / 17 mCoordinates33°40′32″N 117°52′06″W / 33.67556°N 117.86833°W / 33.67556…

Ildefonso Falcones Ildefonso Falcones en Santa María del Mar (Barcelona)Información personalNombre de nacimiento Ildefonso María Falcones de SierraNombre en español Ildefonso Falcones de Sierra Ruc Nacimiento 1959Barcelona, España (65 años)Nacionalidad EspañolLengua materna españolInformación profesionalOcupación abogadoAños activo años 1980-actualidadGénero novela históricaObras notables La catedral del mar (2006)La mano de Fátima (2009)Los herederos de la tierra (2016)Sitio…

Idiom indicating humor or sarcasm A newspaper clipping from 1833, in which a tailor whose coat was stolen from a bowling alley advertises an offer to alter the coat to fit the thief Tongue-in-cheek is an idiom that describes a humorous or sarcastic statement expressed in a serious manner. History The phrase originally expressed contempt, but by 1842 had acquired its modern meaning.[1][2][3] Early users of the phrase include Sir Walter Scott in his 1828 The Fair Maid of Pe…