Code has been added to clipboard!

HTML style Tag

Reading time 2 min
Published Jun 29, 2017
Updated Sep 11, 2019

HTML style Tag: Main Tips

  • Used within <head> or <body>, HTML style tags define internal styling for elements.
  • This styling information contains CSS.
  • It might apply to the whole document or a part of it.
  • HTML inline styles override externally included CSS, but can be overridden by the style attribute.

Defining HTML Inline Style

HTML style tags define CSS styling information that applies to its content:

Example
<head>
<style>

/* This is internal styling */
h1 {
    color: indianred;
}

p {
    color: red;
}

</style>
</head>

You can place HTML style tags in <head> or <body> elements. We'd recommend choosing the first option, as that allows you to keep the content and styling information separate.

Note: you can also use <link> elements to apply styles kept in external stylesheets.

Common style Tag Attributes

There are two attributes you may use with HTML style tags. There is also one that is deprecated and should not be used when modifying style in HTML. However, you should get to know them all.

media is an optional attribute that defines which media should the styling properties affect. Its default value is all:

Example
<style media="screen">

type is an optional attribute describing the styling language as a MIME (Multipurpose Internet Mail Extensions) type. Its default value is text/css:

Example
<style type="text/css">

scoped was a boolean attribute, which set the scope for HTML inline style properties:

Example
<!-- a deprecated attribute -->
<style scoped>

Warning: the scoped attribute has been deprecated in HTML5 and should not be used for style in HTML.

Browser Support

Chrome
1+
Edge
All
Firefox
1+
IE
3+
Opera
3.5+
Safari
1+

Mobile Browser Support

Chrome
18+
Firefox
4+
Opera
10.1+
Safari
1+
Basics
Introduction
Syntax
Editors
Basic Examples
Head Section
<!DOCTYPE>
Tags and Elements
Semantic Elements
Tags Reference
Attributes
Comments
Block and Inline Elements
Forms
Form Elements
Input
Responsive Web Design
Inline Scripts
Uniform Resource Locator
Redirect
XHTML
Geolocation
Drag and Drop
Local Storage
Web Workers
Server-Sent Events
Character Encoding
Text Formatting
Quotation and Citation Elements
Headings
Paragraphs
Links
Tables
Lists
Symbols
Space
Tab
Styles
Computer Code
Layout
Classes
Colors
Images
iframes
Audio Player
Video Player
YouTube Videos
Multimedia
Canvas
SVG
<!-- -->
<a>
<abbr>
<acronym> DEPRECATED
<address>
<applet> DEPRECATED
<article>
<aside>
<audio>
<b>
<base>
<basefont> DEPRECATED
<bdi>
<bdo>
<big> DEPRECATED
<blink> DEPRECATED
<blockquote>
<body>
<br>
<button>
<canvas>
<caption>
<center> DEPRECATED
<cite>
<code>
<col>
<colgroup>
<datalist>
<dd>
<del>
<details>
<dfn>
<dialog>
<dir> DEPRECATED
<div>
<dl>
<dt>
<em>
<embed>
<fieldset>
<figcaption>
<figure>
<font> DEPRECATED
<footer>
<form>
<frame> DEPRECATED
<frameset> DEPRECATED
<h1> – <h6>
<head>
<header>
<hr>
<html>
<i>
<iframe>
<img>
<input>
<ins>
<kbd>
<keygen> DEPRECATED
<label>
<legend>
<li>
<link>
<main>
<map>
<mark>
<menu>
<menuitem> DEPRECATED
<meta>
<meter>
<nav>
<noframes> DEPRECATED
<noscript>
<object>
<ol>
<optgroup>
<option>
<output>
<p>
<param>
<pre>
<progress>
<q>
<rp>
<rt>
<ruby>
<s>
<samp>
<script>
<section>
<select>
<small>
<source>
<span>
<strike> DEPRECATED
<strong>
<style>
<sub>
<summary>
<sup>
<table>
<tbody>
<td>
<tfoot>
<th>
<thead>
<time>
<title>
<tr>
<track>
<tt> DEPRECATED
<u>
<ul>
<var>
<video>
<wbr>