HTML Styles
The style attribute lets you apply CSS directly to a single element. It's the quickest way to change how something looks without a separate stylesheet.
Where styles can live
Common style properties
| Property | Example | Effect |
|---|---|---|
color | color:#04AA6D | Text color |
background-color | background-color:#f1f1f1 | Element background |
font-family | font-family:Verdana,sans-serif | Typeface |
font-size | font-size:18px | Text size |
text-align | text-align:center | Horizontal alignment |
border | border:1px solid #ddd | Border around an element |
Tip: Inline styles are fine for one-off tweaks, but reach for an external stylesheet (or a CSS framework) as soon as you need consistency across pages.
Example
Example
<!DOCTYPE html> <html> <body> <h1 style="color:#04AA6D;">Hello, world!</h1> <p style="font-family:Verdana;font-size:18px;">Styled with the HTML style attribute.</p> </body> </html>Try it Yourself »
Exercise
Make the heading text green using an inline style.
<h1 style="color:
;">Hello</h1>
Use a CSS color name or hex code.
Discussion
Loading…