HTML <style>
tags are used to define the styling rules for an HTML document. The <style>
tag is placed within the <head>
section of an HTML document and contains CSS code that is used to style the content within the HTML document.
Here is an example of how to use the <style>
tag to define the color of text in an HTML document:
<!DOCTYPE html>
<html>
<head>
<style>
/* Define the color of text in the body element */
body {
color: red;
}
</style>
</head>
<body>
<h1>Welcome to my website!</h1>
<p>This is an example of how to use the <style> tag in HTML.</p>
</body>
</html>
In this example, the <style>
tag contains a CSS rule that defines the color of text in the <body>
element to be red. This rule applies to all content within the <body>
element of the HTML document.
You can use the <style>
tag to define any CSS rules that you would normally define in an external CSS file, such as font size, background color, margins, padding, and more. However, it is generally considered better practice to use an external CSS file rather than the <style>
tag for larger projects, as it makes the styling code easier to maintain and reuse.