Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Style & Formatting

HTML lets you control the appearance of your pages in several ways. One simple method is inline styling, which uses the style attribute inside HTML tags.

You have already used structural tags like <h1> and <p>. By default:

But what if you want to change colors, fonts, or alignment? Inline styles allow you to do this.

Inline Style Syntax

You can add styles directly to an HTML element using the style attribute (`style = “property:value;”).

Example

<body>
  <h1 style="color:blue; text-align:center;">This is a Heading</h1>
  <p style="background-color:powderblue; font-family:courier;">
    This is a paragraph.
  </p>
  <p><a href="page2.html">Link to page 2.</a></p>
</body>

Syntax: style="property:value;".

Example

<body>
  <h1 style="color:blue; text-align:center;">This is a Heading</h1>
  <p style="background-color:powderblue; font-family:courier;">
    This is a paragraph.
  </p>
  <p><a href="page2.html">Link to page 2.</a></p>
</body>

More Examples

<! -- blue, centered heading -->
<h1 style="color:blue; text-align:center;">Hello World!</h1>
<! -- paragraph with background color and font -->
<p style="background-color:powderblue; font-family:courier;">
  This is my first HTML page.
</p>

Putting It All Together

Inline styles are written inside quotation marks and can include multiple property-value pairs.

<body>
  <h1 style="color:blue; text-align:center;">Hello World!</h1>
  <p style="background-color:powderblue; font-family:courier;">
    This is my first HTML page.
  </p>
</body>