HTML <style>
Tag
The <style>
tag is used to define the style of an HTML document. It is typically placed inside the <head>
section of the HTML document. This tag allows you to add CSS (Cascading Style Sheets) to your HTML document without using an external stylesheet.
How to use the <style>
tag
Here is an example of how to use the <style>
tag in your HTML document:
<html>
<head>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
}
h1 {
color: blue;
}
</style>
</head>
<body>
<h1>Welcome to my website</h1>
<p>This is a paragraph of text.</p>
</body>
</html>
Attributes of the <style>
tag
Attribute | Description |
type |
Specifies the type of stylesheet language used in the style block. Default value is "text/css". |
media |
Specifies the media type for which the styles are intended. Common values are "all", "print", "screen", "speech". |
Here is an example of using the type
and media
attributes with the <style>
tag:
<style type="text/css" media="screen">
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
}
h1 {
color: blue;
}
</style>
Using the <style>
tag in your HTML document allows you to easily add styles to your content without the need for an external stylesheet. This can help to keep your code organized and make it easier to maintain.