Course contentsShow
← Web Development
Lesson 2181 of 2,98240. Browser DevTools Deep DiveFree lesson

Adding New CSS Rules and Classes

Creating inline styles, adding class names, and inserting new CSS rules to test styling without changing files.

Adding New CSS Rules and Classes

What you'll learn: How to create and test CSS rules and classes directly in DevTools without editing your source files.


When debugging or prototyping designs, you don't always want to switch back to your editor, save files, and reload. Browser DevTools let you experiment with styles in real-time by adding brand-new CSS rules and applying classes on the fly—perfect for testing ideas before committing them to code.

Creating Inline Styles

The quickest way to test a single property is adding an inline style. In the Elements panel, select any element and type directly into the element.style section at the top of the Styles pane. These styles have the highest specificity (except !important), so they override everything else.

Use case: "Does changing this button's padding to 20px look better?"

Adding New CSS Rules

Click the "+" icon (or "New Style Rule" button) in the Styles pane to create a completely new rule. DevTools automatically generates a selector matching your currently selected element, but you can edit it to target anything—classes, IDs, descendant selectors, whatever you need.

Example workflow: Select a <div>, click "+", change the selector to .card, then add properties like border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);

Adding Class Names

In the Elements panel, you can add class names directly to elements. Either:

  • Double-click the element's opening tag and type the class
  • Use the .cls button in the Styles pane to toggle or add classes

This lets you test existing CSS classes from your stylesheets on different elements instantly.

Think of it like: DevTools becomes your CSS sandbox—a safe playground where you can build and break things, then copy the winners back to your actual files.

Key Takeaway: DevTools let you create inline styles, insert new CSS rules with custom selectors, and apply class names dynamically—enabling rapid visual experimentation without touching your source code.