Open original
Info
Demo 2.3

Inline CSS using style=""

You can put CSS directly on an element with the style attribute:

<p style="color: crimson">Hello</p>

No selector, no curly braces ~ you’re already pointing at the element.

Why I’d rather you didn’t

Inline styles beat almost everything else. That sounds handy right up until you want to change the colour of every paragraph and find yourself editing forty of them by hand. Worse, when a stylesheet rule mysteriously “doesn’t work”, an inline style is very often the reason.

They also can’t do :hover, @media queries, or animations. Those need a real stylesheet.

When they’re fine

  • Passing one specific value in, like a custom property or a background image URL that changes per element.
  • Quick throwaway tests. (This is most of what I use them for.)
  • Code generated by a program, where a stylesheet isn’t practical.

For everything else: give it a class.

Next demoInheritence and specificity
Keyboard Shortcuts
⌘ Z / ⌘ ⇧ ZCtrl Z / Ctrl ⇧ Z Undo / redo
Tab / ⇧ TabTab / ⇧ Tab Indent / unindent selection
⌘ ] / ⌘ [Ctrl ] / Ctrl [ Indent / unindent lines
⌘ ACtrl A Select all
⌘ DCtrl D Select next occurrence of selection
⌘ /Ctrl / Comment / uncomment lines
Ctrl SpaceCtrl Space Autocomplete
Ctrl EnterCtrl Enter Reset layout
⌘ ⌥ [ / ⌘ ⌥ ]Ctrl ⇧ [ / Ctrl ⇧ ] Fold / unfold block
Code
The editor didn't load — try refreshing the page. Navigation, shortcuts and the info panel still work in the meantime.
Preview
Dimensions0 × 0
Delay
Console