English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML tag大全

HTML style attribute

The style global attribute includes CSS style declarations applied to the element. Note that styles are best defined in a separate file. The main purpose of this attribute and the <style> element is for quick decoration. For example, for testing purposes.

HTML Global Attributes

Usage Notes:This attribute should not be used to pass semantic information. Even if all styles are removed, the page should retain the correct semantics. It is usually not applied to hide irrelevant information; this should be done using the hidden attribute.

Online Example

Using the style attribute in HTML documents:

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>HTML style attribute usage (Basic Tutorial Website oldtoolbag.com)</title>/title>
</head>
<body>
<h1 style="color:blue;text-align:center">This is a header</h/h1>
<p style="color:green">This is a paragraph.</p>/p>
</body>
</html>
Test it out ‹/›

Browser Compatibility

IEFirefoxOperaChromeSafari

All major browsers support the style attribute

Definition and Usage

The style attribute specifies the inline style of an element.

The style attribute overrides any styles set globally, such as styles specified in <style> tags or external style sheets.

HTML 4.01 with HTML5differences

In HTML5In HTML, the style attribute can be used on any HTML element (it will validate on any HTML element. However, it may not be useful).

In HTML 4.01In HTML, the style attribute cannot be used with <base>, <head>, <html>, <meta>, <param>, <script>, <style>, and <title>.

Syntax

<element style="style_definitions">

Property value

ValueDescription
style_definitionsOne or more CSS properties and values separated by semicolons. (For example: style="color:blue;text-align:center)
HTML Global Attributes