The style Attribute

HTML Styles

The style attribute adds CSS directly to one element:

<tagname style="property:value; property:value;">

Example

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
</head>
<body>

<h1 style="color:#04AA6D; font-family:Verdana;">A styled heading</h1>
<p style="background-color:#282A35; color:white; padding:8px;">White text on a dark background</p>
<p style="font-size:20px; text-align:center;">Large, centered text</p>

</body>
</html>

Result

Three Ways to Add CSS

WayWhereUse for
Inlinestyle attribute on an elementquick tests, one-off overrides
Internal<style> in the <head>a single page
External<link rel="stylesheet" href="styles.css">whole websites (recommended)

Tip: External style sheets let you change the look of an entire site by editing one file. The CSS course covers this in depth.