Free HTML tutorial

HTML Styles: Add CSS to Elements

Learn how the HTML style attribute applies CSS declarations and when to use an external stylesheet for page styling.

What the style attribute does

The HTML style attribute lets you add CSS declarations to one element. The declarations use CSS property names and values.

<p style="color: #26384a; background-color: #f1f5f9;">
  This paragraph has inline CSS.
</p>

Use CSS for reusable presentation

Inline styles can be useful for a small demonstration, but repeating them makes a page harder to maintain. For styles shared across elements or pages, use a stylesheet. HTML can link a separate CSS file from the document head.

<link rel="stylesheet" href="styles.css">

Continue to HTML and CSS basics to learn more about connecting structure with presentation.

Examples