Which HTML attribute specifies inline CSS styles?

The story behind the answer

The HTML attribute that specifies inline CSS styles is style.

Its value contains one or more CSS declarations written directly in an element’s opening tag, such as style="color: red; margin: 1rem;". The browser applies those declarations to that particular element. Multiple declarations are separated by semicolons, and each property is paired with a value using a colon.

The main mix-up is with class and id. The class attribute labels elements so a stylesheet can target groups of them, while id identifies one element and can be used by CSS, JavaScript, or fragment links. Neither attribute directly contains CSS declarations. css is not a standard HTML attribute for applying styles.

Inline styles can be useful for a one-off adjustment or styles generated dynamically by JavaScript, but external or embedded stylesheets are usually easier to maintain. CSS rules in a stylesheet can be reused across many elements, cached by browsers, and changed centrally. Inline declarations also have high cascade precedence compared with ordinary author stylesheet rules, though declarations marked !important can alter that outcome.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: