🌍 ReactJS · subject

ReactJS Styling in React Syllabus

The Styling in React syllabus for ReactJS in full: 3 chapters and 9 topics, every one listed below, plus 49 Styling in React flashcards with answers.

3Chapters
9Topics
49Flashcards

Styling in React syllabus: all 3 chapters

Expand any chapter to see its topics and sub-topics.

  1. CSS in JS

    3 topics
    • Styled-Components
    • Emotion
    • JSS
  2. Preprocessors

    3 topics
    • SASS
    • LESS
    • Stylus
  3. CSS Frameworks

    3 topics
    • Bootstrap
    • Material-UI
    • Tailwind CSS

ReactJS Styling in React flashcards — 49 questions with answers

  1. What is a CSS-in-JS library in the React ecosystem?

    A library that lets you write CSS styles directly within JavaScript/TypeScript files, scoping styles to components and generating unique class names at runtime or build time. Examples include Styled-Components, Emotion, and JSS.

  2. What is Styled-Components?

    A popular CSS-in-JS library that uses tagged template literals to style React components. It creates real React components with styles attached, generates unique class names automatically, and supports theming and dynamic props-based styling.

  3. How do you create a styled button using Styled-Components' tagged template literal syntax?

    const Button = styled.button` color: white; background: blue; `; Then render <Button>Click</Button>. The styled.button call returns a React component with the CSS applied.

  4. In Styled-Components, how do you make styles respond to a component's props?

    Pass a function inside the template literal that receives props: const Btn = styled.button` background: ${props => props.primary ? 'blue' : 'gray'}; `; The interpolated function is evaluated with the component's props.

  5. How do you extend/inherit styles from an existing styled component in Styled-Components?

    Use styled() as a function wrapping the base component: const PrimaryButton = styled(Button)` background: navy; `; This keeps Button's styles and overrides/adds new ones.

  6. How is theming provided in Styled-Components?

    Wrap the app in a <ThemeProvider theme={themeObject}>. Styled components then access theme via props.theme inside interpolations, e.g. ${props => props.theme.primary}. Emotion uses the same ThemeProvider pattern.

  7. What is Emotion in React styling?

    A high-performance, flexible CSS-in-JS library offering two primary APIs: the css prop (@emotion/react) for inline object/string styles, and styled components (@emotion/styled) similar to Styled-Components. Known for small bundle size and source maps.

  8. What is the `css` prop in Emotion and how is it enabled?

    The css prop lets you pass styles directly to any element: <div css={{ color: 'red' }} />. It is enabled via the JSX pragma /** @jsxImportSource @emotion/react */ or Babel/preset configuration so JSX transforms recognize the css prop.

  9. Compare Styled-Components and Emotion.

    Both are CSS-in-JS with tagged-template styled APIs, theming via ThemeProvider, and dynamic props. Emotion additionally offers the css prop and object styles, tends to have a smaller bundle and slightly better performance, while Styled-Components pioneered the styled API and has a large ecosystem.

  10. What is JSS (JavaScript Style Sheets)?

    A CSS-in-JS library that authors styles as JavaScript objects, compiles them to real CSS, and injects them into the DOM. It uses a plugin architecture and was the styling engine underlying Material-UI v4.

  11. In JSS, how are style rules typically written?

    As a JavaScript object where keys are class names and values are objects of CSS property/value pairs, camelCased: const styles = { button: { color: 'white', backgroundColor: 'blue' } }; JSS then generates real CSS and unique class names.

  12. What does the JSS `createUseStyles` hook return?

    It returns a custom React hook (useStyles) that, when called, returns an object mapping your rule names to generated unique class-name strings, which you then apply to elements via className={classes.button}.

  13. What is SASS/SCSS?

    Sass (Syntactically Awesome Style Sheets) is a CSS preprocessor that extends CSS with variables, nesting, mixins, functions, inheritance, and partials. SCSS is its CSS-compatible syntax; both compile to plain CSS before the browser sees them.

  14. What are the two syntaxes of Sass?

    1) The indented syntax (.sass files) which omits braces and semicolons and uses indentation. 2) SCSS (.scss files) which uses braces and semicolons and is a superset of CSS3, making it the more common modern choice.

  15. How do you declare and use a variable in SCSS?

    Prefix with a dollar sign: $primary: #3498db; then use it: color: $primary;. Sass variables are resolved at compile time (unlike CSS custom properties which are runtime).

  16. What is a mixin in Sass and how is it used?

    A reusable block of declarations defined with @mixin name(args) and included with @include name(args). Example: @mixin flex-center { display: flex; justify-content: center; align-items: center; } .box { @include flex-center; }

  17. What does Sass nesting allow, and what is the `&` selector?

    Nesting lets you write child/related selectors inside a parent block, mirroring HTML structure. The & references the parent selector, useful for pseudo-classes and modifiers, e.g. &:hover or &.active.

  18. How do you integrate SASS into a React project?

    Install the sass package (npm install sass), then import .scss/.sass files directly in components: import './App.scss'. Bundlers like Vite and Create React App detect sass and compile it automatically. CSS Modules work too via file.module.scss.

  19. What is LESS?

    A CSS preprocessor (Leaner Style Sheets) similar to Sass, adding variables, mixins, nesting, operations, and functions. It compiles to CSS and was historically associated with Bootstrap (v3) and Ant Design.

  20. How do you declare a variable in LESS versus SASS?

    LESS uses the @ prefix: @primary: #3498db; while SASS uses the $ prefix: $primary: #3498db;. Both are resolved at compile time. (Note: @ can be ambiguous with CSS at-rules, one reason many prefer Sass's $.)

Show the other 29 Styling in React flashcards
  1. How are mixins written in LESS?

    Any class or id ruleset can be reused as a mixin by referencing it: define .rounded { border-radius: 8px; } and include with .rounded(); inside another selector. Parametric mixins accept arguments: .border(@w) { border: @w solid; }.

  2. What is Stylus (CSS preprocessor)?

    An expressive, minimalist CSS preprocessor written in Node.js. Its most notable feature is optional/omittable syntax: colons, semicolons, braces, and even the class delimiters can be dropped, relying on indentation and whitespace.

  3. How do Stylus variables and its optional syntax look?

    Variables need no sigil: primary = #3498db. Rules can drop braces/colons/semicolons: body color primary font-size 16px Stylus infers structure from indentation, making it the most flexible-syntax preprocessor.

  4. Classify the main CSS preprocessors and their language/runtime.

    Sass (Ruby originally, now Dart/LibSass; uses $), LESS (JavaScript-based; uses @), and Stylus (Node.js-based; optional syntax, no sigil). All add variables, nesting, mixins, and functions and compile down to plain CSS.

  5. What is Bootstrap?

    A widely used open-source CSS framework providing a responsive 12-column grid, pre-built components (buttons, navbars, modals, cards), and utility classes. Styled via predefined class names rather than writing custom CSS.

  6. How many columns does Bootstrap's grid system use, and how is it structured?

    Bootstrap's grid uses 12 columns. Layout is built with .container > .row > .col-* elements; column classes like col-md-6 span a fraction of the 12 columns at given breakpoints, so col-md-6 spans half the row on medium+ screens.

  7. What is the recommended way to use Bootstrap with React?

    Use React-Bootstrap or Reactstrap, which reimplement Bootstrap components as actual React components (e.g. <Button variant="primary">) without jQuery, giving idiomatic props and state instead of raw class strings.

  8. List Bootstrap's default responsive breakpoint tiers.

    Extra small (xs, <576px, no infix), small (sm, ≥576px), medium (md, ≥768px), large (lg, ≥992px), extra large (xl, ≥1200px), and extra extra large (xxl, ≥1400px) in Bootstrap 5.

  9. What is Material-UI (MUI)?

    A comprehensive React component library implementing Google's Material Design. It provides ready-made, accessible, themeable components (Button, TextField, Grid, etc.) and, since v5, uses Emotion (styled-engine) for styling, replacing JSS used in v4.

  10. What styling engine does Material-UI (MUI) v5 use, and what did it use before?

    MUI v5 uses Emotion as its default styling engine (with an option for Styled-Components). MUI v4 used JSS with the makeStyles/withStyles APIs.

  11. What is the `sx` prop in MUI?

    A shortcut prop available on MUI components for applying one-off theme-aware styles via an object, e.g. <Box sx={{ mt: 2, color: 'primary.main' }} />. It supports theme tokens, responsive values, and shorthand spacing.

  12. How does MUI's `styled` utility differ from creating a plain styled component?

    MUI's styled (from @mui/material/styles) is theme-aware by default: the callback receives ({ theme }) so you can reference theme.spacing, theme.palette, and breakpoints, and it integrates with MUI's component slots and variants.

  13. What is Tailwind CSS?

    A utility-first CSS framework where you compose designs by applying small single-purpose classes (e.g. flex, pt-4, text-center, bg-blue-500) directly in markup, rather than writing custom CSS or using pre-built components.

  14. What does 'utility-first' mean, and how does Tailwind differ from Bootstrap?

    Utility-first means styling by combining atomic classes each doing one thing (padding, color, flex) directly in HTML. Bootstrap is component-first, shipping pre-designed components; Tailwind gives low-level primitives so you build custom designs without leaving your markup.

  15. How does Tailwind keep the production CSS bundle small?

    Tailwind scans your source files (the content paths in tailwind.config) and generates only the utility classes you actually use, purging/tree-shaking all unused classes. This just-in-time compilation yields a very small final CSS file.

  16. How are responsive styles written in Tailwind CSS?

    Prefix a utility with a breakpoint name and colon: sm:, md:, lg:, xl:, 2xl:. For example <div class="text-sm md:text-lg"> is small text by default and large on medium+ screens. Tailwind is mobile-first, so unprefixed utilities apply to all sizes.

  17. What file configures Tailwind's design tokens and where do custom colors go?

    tailwind.config.js (or .ts). Custom design tokens live under theme (or theme.extend to add without replacing defaults), e.g. theme.extend.colors.brand = '#123456', which then generates classes like bg-brand.

  18. What are the two main categories of React styling approaches?

    1) CSS-based/traditional: plain CSS, CSS Modules, and preprocessors (SASS, LESS, Stylus) plus utility frameworks (Tailwind, Bootstrap). 2) CSS-in-JS: styles written in JavaScript (Styled-Components, Emotion, JSS). They differ in scoping, runtime cost, and colocation.

  19. What problem do CSS Modules and CSS-in-JS both solve?

    Global namespace collisions. Both automatically scope styles to a component by generating unique/hashed class names, so styles in one component cannot unintentionally leak into or override another.

  20. What is a key trade-off of runtime CSS-in-JS (e.g. Styled-Components) versus utility CSS (Tailwind)?

    Runtime CSS-in-JS generates and injects styles as JS executes, adding runtime overhead and bundle weight but enabling dynamic prop-driven styles. Utility CSS like Tailwind ships static, pre-purged CSS with near-zero runtime cost but less dynamic flexibility.

  21. Compare compile-time variables (Sass/LESS) with CSS custom properties for dynamic theming.

    Sass/LESS variables are resolved at compile time and are fixed in the output CSS, so they cannot change at runtime. CSS custom properties (--var) are live and can be updated at runtime via JavaScript or media queries, making them better for dynamic theming.

  22. Which styling libraries share the `ThemeProvider` + `theme` prop pattern?

    Styled-Components and Emotion both use a ThemeProvider component and expose the theme via props.theme (or theme in the styled callback). MUI also provides its own ThemeProvider building on Emotion.

  23. What is the purpose of the `createGlobalStyle` helper in Styled-Components?

    It creates a component that injects global CSS (resets, body/html styles, font-face) into the document rather than scoping it to one component. You render <GlobalStyle /> once near the app root.

  24. In Emotion, what is the difference between the object-style and string-style css API?

    Object style uses a JS object with camelCased properties: css({ fontSize: 12 }). String style uses a tagged template with normal CSS syntax: css`font-size: 12px;`. Both produce a class name; object style avoids parsing template strings and enables easy composition.

  25. What is `@apply` in Tailwind CSS used for?

    @apply lets you inline existing Tailwind utility classes inside a custom CSS rule, e.g. .btn { @apply px-4 py-2 rounded bg-blue-500; }. It extracts repeated utility combinations into a reusable component class within a CSS file.

  26. How do you conditionally combine classes in a React component (relevant to Tailwind/Bootstrap)?

    Use template literals or a helper like clsx/classnames: className={clsx('btn', isActive && 'btn-active')}. This toggles utility or component classes based on state/props without manual string concatenation errors.

  27. What are the key selling points of Tailwind's JIT (Just-In-Time) engine?

    On-demand generation of only used classes (small builds), support for arbitrary values like w-[137px], faster build times, and enabling all variants (hover, focus, responsive) without pre-generating huge stylesheets.

  28. Summarize when to choose CSS Modules + SASS versus Tailwind versus CSS-in-JS.

    CSS Modules + SASS: scoped styles with familiar CSS/preprocessor power and no runtime. Tailwind: rapid, consistent UI via utilities with tiny static output. CSS-in-JS (Styled-Components/Emotion): dynamic, prop-driven, colocated component styling with theming, at some runtime cost.

  29. What role did JSS play historically in the React styling landscape, and why did MUI move away from it?

    JSS was an early, plugin-based CSS-in-JS solution and the styling engine of Material-UI v4 (makeStyles/withStyles). MUI v5 migrated to Emotion for better performance, a simpler API (styled/sx), and improved developer experience, so JSS usage has since declined.

ReactJS Styling in React FAQ

What is in the ReactJS Styling in React syllabus?

ReactJS Styling in React is split into 3 chapters: CSS in JS, Preprocessors and CSS Frameworks. Together they contain 9 topics.

How many chapters are in ReactJS Styling in React?

3 chapters, containing 9 topics. The largest chapter is CSS in JS, with 3 topics.

Are there flashcards for ReactJS Styling in React?

Yes — a 49-card Styling in React deck, printed in full in the flashcards section of this page and available in the Examius app with spaced repetition. The free plan covers one exam of your choice, including its flashcards; Examius Pro, a one-time purchase, unlocks every other exam and deck.