Skip to content
Learn Netverks

Lesson

Step 23/36 64% through track

classnames-inline

Class names and inline styles

Last reviewed May 28, 2026 Content v20260528
Track mode
client_react
Means
In-browser React TSX
Reading
~2 min
Level
intermediate

This lesson

This lesson teaches Class names and inline styles: the concepts, APIs, and habits you need before advancing in React.

Without Class names and inline styles, you will struggle to read or extend React codebases and playground exercises.

You will apply Class names and inline styles in contexts like: SPAs, dashboards, design-system-driven products, and React Native mobile apps.

Write TypeScript/TSX, click Run in browser—React 18 loads from CDN, JSX compiles in the tab, UI renders in the preview root, and printOutput feeds the terminal.

When you can explain the previous lesson's ideas without copying starter code.

React components usually style UI with CSS classes (global, CSS modules, or utility frameworks) or occasional inline styles for one-off dynamic values. The playground has no build step—use plain className strings and object styles like production, minus Sass imports.

className, not class

JSX uses className because class is reserved in JavaScript. Apply static classes as strings; combine conditional classes with template literals or a small helper array joined with spaces.

const base = 'badge';
const tone = isError ? 'badge-error' : 'badge-ok';
return <span className={`${base} ${tone}`}>Status</span>;

Inline style objects

style accepts a camelCased object. Values are often strings with units. Prefer classes for layout; use inline styles when a value is computed at runtime (width from data, dynamic theme token).

<div style={{ width: `${pct}%`, opacity: disabled ? 0.5 : 1 }} />

Interview angle

  1. Q: className vs style?
    A: Classes scale with design systems and pseudo-states; inline styles suit dynamic numeric values but do not support media queries or :hover without libraries.
  2. Q: Why avoid inline styles for everything?
    A: Harder to reuse, no pseudo-classes, and larger rerender payloads when objects are recreated each render.

Self-check

  1. When would you pick inline style over a CSS class?
  2. How do you toggle two classes based on a boolean prop?

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs in your browser in a sandboxed frame. Backend runners appear when this track’s profile allows them.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • className strategy?
  • Inline style trade-off?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump